注销后如何保持 Perl 脚本在 Unix 上运行?

发布于 2024-10-20 09:42:45 字数 625 浏览 9 评论 0原文

我有一个需要很长时间才能完成的脚本。

我宁愿注销并稍后检索其输出,而不是等待它完成。

我已经尝试过了;

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

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

我也验证了这些进程实际上存在于 psat -l 中,具体取决于我使用的调度语法。

当我退出 shell 时,这两个进程都会终止。有没有办法在关闭连接时阻止脚本终止?

我们这里有 cron,它们已设置并正常工作,但我想使用 atnohup 作为一次性脚本。

我的语法有问题吗?还有其他方法可以产生预期的结果吗?


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

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 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

忘羡 2024-10-27 09:42:45

使用屏幕。它创建一个终端,当您注销时该终端会继续运行。当您重新登录时,您可以切换回原来的状态。

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

像你 2024-10-27 09:42:45

如果您想在注销后保持进程运行:

disown -h

是一个有用的 bash 内置函数。与 nohup 不同,您可以在已运行的进程上运行 disown

首先,使用 control-Z 停止工作,从 ps 获取 pid(或使用 echo $!),使用 bg 将其发送到背景,然后使用 disown 和 -h 标志。

不要忘记将您的作业设置为后台,否则当您注销时它会被杀死。

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.

撩心不撩汉 2024-10-27 09:42:45

这只是一个猜测,但我在某些版本的 ssh 和 nohup 中看到过:如果您使用 ssh 登录,那么您可能需要重定向 stdout、stderr stdin 以避免当您退出时让会话挂起。 (其中一个可能仍然连接到终端。)我会尝试:(

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

我当前版本的 ssh 和 nohup 不再是这种情况 - 后者如果检测到任何连接到终端,就会重定向它们 - 但你可能使用不同的版本。)

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.)

南风起 2024-10-27 09:42:45

nohup 的语法看起来没问题,但您的帐户可能不允许进程在注销后运行。另外,尝试将 stdout/stderr 重定向到日志文件或 /dev/null。

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.

盗心人 2024-10-27 09:42:45

在后台运行您的命令。

/path/to/./thescript.pl &

获取后台作业的列表

   jobs

现在,您可以有选择地拒绝上述任何作业及其 jobid。

disown <jobid>

即使您注销后,所有被拒绝的进程也应继续运行。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文