use strict; use warnings; use Net::OpenSSH; use MIME::Base64; my $host = $ARGV[0]; my $ssh = Net::OpenSSH->new(user => 'user', password => decode_base64('my_b64_encoded_pass'), host => $host, timeout => '3', # master_stderr_discard => 1, # master_opts => [-o =>'RemoteCommand="sx su - targetuser"'] ); die "Can't ssh to $host: " . $ssh->error if ($ssh->error); foreach my $cmd('echo "VAR=$VAR"', 'id', 'export VAR="test";echo $VAR', 'echo "VAR=$VAR"') { my $output=$ssh -> system ($cmd); $ssh->error and warn "$cmd didn't complete successfully: ". $ssh->error; print $output; }