Using Net::SSH2, I've debugged the reason why your remote process doesn't return control quick enough, you need to daemonize your remote child. See perlipc on how to dissociate a child process from its parent.

The following code uses Net::SSH2, because that is what I have available but should be easily adapted to any other SSH client. The interesting part is the oneliner string that is basically the daemonize subroutine. In my test case, the remote process simply sleeps three seconds and then creates a file:

#!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';

The output is as expected, after roughly three seconds, the file gets created by the remote process:

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/nul +l";$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

In reply to Re^6: untaring at remote location by Corion
in thread untaring at remote location by t-rex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.