开发者

How do I keep a Perl script running on Unix after I log off?

I have a script that takes a lot of time to complete.

Instead of waiting for it to finish, I'd rather just log out and retrieve its output later on.

I've tried;

at -m -t 03030205 -f /path/to/./thescript.pl

nohup /path/to/./thescript.pl &

And I have also verified 开发者_JS百科that the processes actually exist with ps and at -l depending on which scheduling syntax i used.

Both these processes die when I exit out of the shell. Is there a way to keep a script from terminating when I close the connection?

We have crons here and they are set up and are working properly, but I would like to use at or nohup for single-use scripts.

Is there something wrong with my syntax? Are there any other methods to producing the desired outcome?


EDIT:

I cannot use screen or disown - they aren't installed in my HP Unix setup and i am not in the position to install them either


Use screen. It creates a terminal which keeps going when you log out. When you log back in you can switch back to it.


If you want to keep a process running after you log out:

disown -h <pid>

is a useful bash built-in. Unlike nohup, you can run disown on an already-running process.

First, stop your job with control-Z, get the pid from ps (or use echo $!), use bg to send it to the background, then use disown with the -h flag.

Don't forget to background your job or it will be killed when you logout.


This is just a guess, but something I've seen with some versions of ssh and nohup: if you've logged in with ssh then you may need to need to redirect stdout, stderr and stdin to avoid having the session hang when you exit. (One of those may still be attached to the terminal.) I would try:

nohup /path/to/./thescript.pl > whatever.stdout 2> whatever.stderr < /dev/null &

(This is no longer the case with my current versions of ssh and nohup - the latter redirects them if it detects that any is attached to a terminal - but you may be using different versions.)


Syntax for nohup looks ok, but your account may not allow for processes to run after logout. Also, try redirecting the stdout/stderr to a log file or /dev/null.


Run your command in background.

/path/to/./thescript.pl &

To get lits of your background jobs

   jobs

Now you can selectively disown any of the above jobs, with its jobid.

disown <jobid>

All the disowned process should be keep on running even after you logged out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜