Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: untaring at remote location

by Corion (Patriarch)
on Jun 16, 2016 at 07:07 UTC ( [id://1165824]=note: print w/replies, xml ) Need Help??


in reply to Re^3: untaring at remote location
in thread untaring at remote location

I think the child will also need to ignore the HUP signal:

$SIG{SIGHUP} = 'ignore';

But personally, I would instead look at the nohup manpage and just use that.

Also, your error description doesn't really help me help you with your problem as you don't tell us what exactly happens.

Replies are listed 'Best First'.
Re^5: untaring at remote location
by t-rex (Scribe) on Jun 16, 2016 at 08:36 UTC

    the error is basically my host script hangs up....coz the server when started (on remote by sabkuch.pl) doesn't end as it is a while (1) keep listening to port my point is can u help me with have a parent process which forks out a child and exits. now this child will keep running ( server.pl) till the machine is on or something weird happens. I hope i can make myself clear

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1165824]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-24 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found