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

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' +);

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

    Hi Salva,

    Ok, I've gotten it working now, the trick is to break up the command, surrounded by single quotes, so that su doesn't think it is being passed parameters.

    However, I still always get the below error when the capture method is called.

    tcgetattr: Invalid argument

    I suppose it isn't a showstopper, but it makes the output of the script quite ugly with all these error lines coming through. I suppose there is no way of silencing this error?

    regards,

    Tim

      Try also setting stderr_discard => 1 on the capture call.

        Hi Salva,

        Unfortunaytely that doesn't work. Note I also do something similar in the ssh constructor as in:

        my $ssh = Net::OpenSSH->new($master_host, user => "loguser", master_st +derr_discard => 1, expand_vars => => 1);

        Anything else I can try?

        Tim