tim.culhane has asked for the wisdom of the Perl Monks concerning the following question:
hi, I'm trying to use Net::OpenSSH to su to another user account, issue a command and capture the output of that command in my perl script. I need to use sudo for the su command in order to get permission to switch users. The code I have right now is:
#!/usr/bin/perl use Net::OpenSSH; my $host = "enfcdb01"; my $user = "loguser"; my $password = "cIhyv46iPL8092t"; ##-- set up a new connection my $ssh = Net::OpenSSH->new($host, user => "loguser"); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->err +or; my @ls = $ssh->capture("ls"); $ssh->error and die "remote ls command failed: " . $ssh->error; print @ls; my @out = $ssh->capture({tty => 1, stdin_data => "$password\n"}, 'sudo', '-Sk', '-p', '', '--', 'su - imail; ls'); print "the value of out is \n"; print "$out[0]";
and the output I get is:
loguser@enflog01 check_apps$ ./check_mx_app.pl id_rsa.pub muxserver_accept_control: tcgetattr: Invalid argument tcgetattr: Invalid argument the value of out is
Anybody know what is wrong with my capture call? Thanks, Tim
|
|---|