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

sudo: sorry, you must have a tty to run sudo

You are using an old version of sudo. Update it if you can.

I get my original error back again:
muxserver_accept_control: tcgetattr: Invalid argument tcgetattr: Inval +id argument

This error is harmless, you can safely ignore it. Also, you can silence it adding the following option into the constructor call: master_stderr_discard => 1

sudo su -c "pwd" imail /home/loguser
This seems to just report the current working directory of the loguser user

Add the flag -l to the su command: sudo su -lc "pwd" imail

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

    Hi again,

    Unfortunately the system is locked down so upgrading sudo is not an option. Anyway, adding tty >=1 seems to fix that error?

    I added the master_stderr_discard option to the constructor and one of the error lines has gone away:

    " muxserver_accept_control: tcgetattr: Invalid argument "

    but I still get one instance of

    " tcgetattr: Invalidargument "

    So, using the below code I still can't seem to get access to the imail account:

    my @out = $ssh->capture({ tty => 1, stdin_data => "$password\n" }, 'sudo', '-Sk', '-p', '', '--', 'su -lc "ls" imail');

    Any ideas as to what I'm still doing wrong?

    tim

      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"

        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