Search code examples
perlserver-administration

How can I capture the output of remote commands then issue more remote commands?


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


Solution

  • 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
    }