Thanks salva for your reply, but it's not quite what i am looking for.
Think about my sx thingie like it's gnu screen. I would like to ssh 'into' screen directly, instead of launching it as a command.
i noticed also other thing: while running commands in loop, they're acting like being launched over separate ssh connections. Consider following code
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 s
+u - 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 ($cm
+d);
$ssh->error and
warn "$cmd didn't complete successfully: ". $ssh->error;
print $output;
}
It produces output
VAR=
1uid=xxx(user) gid=yyy(group)
1test
1VAR=
I didn't found method which allows "connection" to be kept between system() or capture() calls, or i am doing something awfully wrong. My ultimate goal is to check exitcode after each line of (externally loaded) script and perform action if something fails, but without some initializations with exporting variables my whole idea collapses :/ i don't want to produce nasty workaround like env > /tmp/envfile and sourcing it prior to actual command. Does Openssh foresee mechanism to continue/append to existing connection? I love concept of warn $ssh-> error if $ssh-> error, hence i don't want to look for other modules, and surely i don't want to utilize any Expect-like tools. |