views:

105

answers:

3

Hi,

I am running a script where it login to a server then executes the command "passwd -n 0 -x 99999 -i -1 debug" for removing ageing of the debug user. If the user debug is not present then I want to create the user debug, change the password it, and then execute the above command for ageing.

How can I do?

Regards, vasistha

A: 

Use puppet.

If you really insist on doing it manually, use getent passwd debug to check whether the user exists:

if [ $(getent passwd debug | wc -l ) = 0 ]; then
    adduser debug
fi
David Schmitt
+1  A: 

From perlfunc(1):

          system LIST
               [...]
               The return value is the exit status of the program as returned
               by the "wait" call.  To get the actual exit value, shift right
               by eight (see below).

Therefore:

my $ret = system(qw/passwd -n 0 -x 99999 -i -1 debug/);
if ($ret != 0) {
  # failure handling code here
}
hhaamu
How does this answer the question? system() runs something on the same machine. It doesn't execute anything on the remote server.
brian d foy
Eh, now that I re-read the question, I don't know either. I didn't notice the remote part. Would it be a stretch to think that the perl script is uploaded to the server?
hhaamu
A: 

I suggest using something like Expect. It handles the interactivity for you. You can log in to the server, execute commands, inspect the output, send more input, and so on. If you are doing lots of remote server administration, it's a very handy tool to know. There's even an article about it in The Perl Review Issue 4.2 (Spring 2008)

brian d foy