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

Hi Monks,
I have to run a script on a remote server which take a long time to run.
Is there anyway to run it without waiting the output on local server ? Process on the local server should finish immediately after initiating the script on remote server. I tried ssh/rsh but it waits till the script is finished on remote server. Any help is greatly appreciated.

Replies are listed 'Best First'.
Re: Run a remote script
by Old_Gray_Bear (Bishop) on Jul 13, 2004 at 21:36 UTC
    Fork a child process off to initiate the ssh/rsh remote process and let the parent go on about its business. Note: make certain that the child has enough intelligence built in to act appropriately when confronted with an error. I am very fond of sending an email reguardless of the outcome. I always get confirmation that the child process completed.

    ----
    I Go Back to Sleep, Now.

    OGB

Re: Run a remote script
by superfrink (Curate) on Jul 14, 2004 at 00:50 UTC
    Check out nohup (section 1 of the man pages). On some systems (I believe Solaris for eg) when you close your ssh connection all of the open jobs you have open are sent a HUP signal. Chances are your program is being killed by this signal (many are). Using nohup will cause the HUP to be ignored so your process won't die when you log out. You just run your command as " nohup my_background_job & " instead of as " my_background_job & ". Let us know if that helps solve it.

      If the jobs are left running or killed is a function of the shell. For example (IIRC), csh, by default, will let them run. On the other hand, ksh, will not. You can change that behavior by nohupping under some shells, disconnecting from the process group and terminal, stty tostop, etc.

      --MidLifeXis

Re: Run a remote script
by ajwans (Scribe) on Jul 14, 2004 at 01:18 UTC
    I prefer to use screen. You can start your script, detach the current screen, and then log back in later & reattach to see what the results were.

    andy


    "Don't you hate it when people quote themselves?" - me
Re: Run a remote script
by qq (Hermit) on Jul 13, 2004 at 21:38 UTC

    I mayn not be understanding you, but could you ust put the process into the background? Then you won't be waiting on output.

    > ./run_this_script &

    qq