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;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|