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

What happens when you run the following command from your local machine command line?
echo $SUDO_PASSWORD |ssh host "sudo -Sk -p '' -- su -lc ls imail"

Replies are listed 'Best First'.
Re^6: Problem using Net::OpenSSH->capture to su to another user
by tim.culhane (Initiate) on Jun 04, 2014 at 12:59 UTC

    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

      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?