in reply to Re^5: Problem using Net::OpenSSH->capture to su to another user
in thread Problem using Net::OpenSSH->capture to su to another user

Hi Salva,

If I try that I get the below output:

loguser@enflog01 check_apps$ echo <password> |ssh loguser@enfcdb01 "sudo -Sk -p '' -- su -lc ls imail" sudo: sorry, you must have a tty to run sudo

tim

  • Comment on Re^6: Problem using Net::OpenSSH->capture to su to another user

Replies are listed 'Best First'.
Re^7: Problem using Net::OpenSSH->capture to su to another user
by salva (Canon) on Jun 04, 2014 at 13:09 UTC
    oops, try again forcing a tty allocation!
    echo $PASSWD |ssh -tt loguser@enfcdb01 "sudo -Sk -p '' -- su -lc ls im +ail"

    (BTW, you may like to remove the password from your previus post)

      Hi Salva,

      That command sort of seems to work in that the 'ls' command works but there is still an error. I get:

      loguser@enflog01 check_apps$ echo cIhyv46iPL8092t |ssh -tt loguser@enfcdb01 "sudo -Sk -p '' -- su -lc ls imail" tcgetattr: Invalid argument We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. Mx9.0 check_mx_config.sh etc include log perl sleepycat tmp bin config examples lib man queue snmp upgrade Connection to enfcdb01 closed.

      I added a foreach statement in my code to see what was being returned for the capture call. The code is as follows.

      <code> my @out = $ssh->capture({ tty => 1, stdin_data => "$password\n" }, 'sudo', '-Sk', '-p', '', '--', 'su -lc "ls" imail'); foreach (@out) { print "the value of out is ". $_; }

      And the output is:

      tcgetattr: Invalid argument the value of out is the value of out is We trust you have received the usual lecture from the local System the value of out is Administrator. It usually boils down to these three things: the value of out is the value of out is #1) Respect the privacy of others. the value of out is #2) Think before you type. the value of out is #3) With great power comes great responsibility. the value of out is the value of out is the value of out is sudo: su -lc "ls" imail: command not found

      Not sure if this something to do with the shell not interpreting the command being sent?

        Well, you will have to read the documentation for your particular version of sudo and find out why it is failing, which one is the "invalid argument".

        Regarding the Perl part, sudo does not expect the subcommand and its arguments passed combined into a single argument. Try as follows:

        $ssh->capture({ tty => 1, stdin_data => "$password\n" }, 'sudo', '-Sk', '-p', '', '--', 'su', '-lc', 'ls', imail' +);
        Tim, you may want to remove that password from this post as well.