Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^7: A little demo for Net::SSH2

by zentara (Archbishop)
on Nov 15, 2010 at 18:20 UTC ( #871530=note: print w/replies, xml ) Need Help??


in reply to Re^6: A little demo for Net::SSH2
in thread A little demo for Net::SSH2

Hi, you need both nohup and &, AND some minimal daemonizing. :-)

I just tested this, and I see what the problem is. To run the program in the background, you need to close up/redirect it's stdin,stdout,stderr filehandles, like in the daemonization process. Anyways, this syntax works.

#!/usr/bin/perl use warnings; use strict; use Net::SSH2; my $ssh2 = Net::SSH2->new(); #using keys authorization my $pass = 'ztester'; $ssh2->connect('localhost') or die "Unable to connect Host $@ \n"; # works when run from z's homedir because you need # permission to read the keys $ssh2->auth_publickey('zentara', '/home/zentara/.ssh/id_dsa.pub', '/home/zentara/.ssh/id_dsa', $pass ); my $chan = $ssh2->channel(); $chan->blocking(1); #close up the filehandles... rename foo to whatever you want $chan->exec("nohup /home/zentara/perlplay/net/zzsleep > foo.out 2> foo +.err < /dev/null &"); $chan->send_eof; exit;
The zzsleep program is simply
#!/usr/bin/perl $|= 1; while(1){ print time, "\n"; sleep 1; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-10-07 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (30 votes). Check out past polls.

    Notices?