bhushanQA has asked for the wisdom of the Perl Monks concerning the following question:

I have below Perl code where I am executing the java program on remote machine using NET:SSH:Expect. I want java script to be run in background for my requirement but once I exit from the Perl code my java scripts running in background gets automatically killed. Please suggest any solution.
#!/usr/bin/perl #use strict refs; #use warnings; use Expect; use Net::SSH::Expect; my $ssh = Net::SSH::Expect-> new ( host => "MYHOST", password => "user123", user => "user123", raw_pty => 1, log_file => "log_file" # this line actually got my head spinn +ing in right direction ); my $login_output=$ssh->login(); sleep 1; my $output=$ssh->exec("pwd"); warn "$output\n"; $ssh->exec("/sbin/fuser -k 9090/tcp"); my $output1=$ssh->exec("cd /home/tecnomen/JanusSIM2.0"); warn "$output1\n"; $ssh->exec("javac Atsi2.java"); sleep 1; warn "starting the ATSI script\n"; my $output3=$ssh->exec("java Atsi2 &"); sleep 10; warn"$output3\n";

Replies are listed 'Best First'.
Re: Net::SSH::Expect --> Process is quite after exiting from program.
by salva (Canon) on Feb 14, 2017 at 09:38 UTC
    Launch the remote program with nohup:
    $ssh->exec("nohup java Atsi2 >/dev/null 2>&1 </dev/null &");

    In any case, Net::SSH::Expect is quite unreliable, any other Perl SSH module available is probably a better option.

Re: Net::SSH::Expect --> Process is quite after exiting from program.
by marto (Cardinal) on Feb 14, 2017 at 09:20 UTC

    My suggestion would be to either write a short shell script to create a proper service to start/stop this, which you could then operate as normal (and/or via ssh), or figure out how to use the spawn Expect command to ignore the hangup signal. If I had to choose I'd go with the service option.