I havn't tested this, but try running the command with nohup, see "man nohup".
$chan1->exec("nohup ./a.out ");
| [reply] [d/l] |
Explain "does not work". What do you expect, what happens instead? Any messages?
Add error checks to your code.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] |
Hi,
zentara: No still does not work.
afoken:
Does not work means as follow: I run the perl script (Net::SSH2) in my machine host1, which is supposed to run a command "a.out" in machine host2. If I do
$chan1->exec("./a.out");
I can see in host2 this program running. (by command ps or top)
But if I do
$chan1->exec("./a.out &");
or
$chan1->exec("nohup ./a.out"); (as zentara suggested)
I do not see any program running in host2.
The machines are NFS mounted, so all machines can see same home directory. | [reply] [d/l] [select] |
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;
}
| [reply] [d/l] [select] |