#!perl -w use strict; use Net::SSH2; my $remote_cmd = q{perl -MPOSIX=setsid -wle 'close STDIN;open STDOUT,">","/dev/null";$SIG{HUP}="ignore";fork and exit;setsid;sleep 3; open my $fh, ">", "/tmp/test.txt" or die $!'}; my $ssh = Net::SSH2->new(); $ssh->connect('mychat.dyn.datenzoo.de'); $ssh->auth(username => 'corion', password => 'rGj3HVR4'); sub run($) { my $ch = $ssh->channel; $ch->ext_data('merge'); my $cmd = shift; print "remote>$cmd\n"; $ch->exec($cmd) or die $ssh->error; my ($out,$err) = ('',''); $ch->send_eof; while(!$ch->eof) { if (my ($o, $e) = $ch->read2) { $out .= $o; $err .= $e; } #else { # $ssh->die_with_error; #} }; print $out; print $err; }; run 'rm /tmp/test.txt'; run 'ls -altr /tmp/test.txt'; run $remote_cmd; sleep 1; run 'ls -altr /tmp/test.txt'; sleep 1; run 'ls -altr /tmp/test.txt'; sleep 1; run 'ls -altr /tmp/test.txt'; #### C:\Users\Corion\Projekte>perl -w tmp.pl remote>rm /tmp/test.txt remote>ls -altr /tmp/test.txt ls: File not found: /tmp/test.txt remote>perl -MPOSIX=setsid -wle 'close STDIN;open STDOUT,">","/dev/null";$SIG{HUP}="ignore";fork and exit;setsid;sleep 3; open my $fh, ">", "/tmp/test.txt" or die $!' Filehandle STDIN reopened as STDOUT only for output at -e line 1. remote>ls -altr /tmp/test.txt ls: File not found: /tmp/test.txt remote>ls -altr /tmp/test.txt ls: File not found: /tmp/test.txt remote>ls -altr /tmp/test.txt -rw-r--r-- 1 corion corion 0 Jun 16 18:49 /tmp/test.txt