执行即使我注销也能运行的脚本 [英] executing a script which runs even if i log off

查看:47
本文介绍了执行即使我注销也能运行的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个运行时间很长的脚本(大约几天),说 execute.sh ,我打算在具有用户帐户的服务器上执行该脚本...

So, I have a long running script (of order few days) say execute.sh which I am planning to execute on a server on which I have a user account...

现在,我想执行此脚本,以便即使我注销或与服务器断开连接也可以永远运行?我怎么做?谢谢

Now, I want to execute this script so that it runs forever even if I logoff or disconnect from the server?? How do i do that? THanks

推荐答案

您有两种选择.最基本的是使用 nohup :

You have a couple of choices. The most basic would be to use nohup:

nohup ./execute.sh

nohup 作为子进程执行该命令,并从终端分离并在收到 SIGHUP 后继续运行.此信号表示 sig挂断,如果您关闭终端并且仍连接有进程,则会触发该信号.

nohup executes the command as a child process and detaches from terminal and continues running if it receives SIGHUP. This signal means sig hangup and will getting triggered if you close a terminal and a process is still attached to it.

该进程的输出将重定向到当前目录中的默认 nohup.out 文件.

The output of the process will getting redirected to a file, per default nohup.out located in the current directory.

您还可以使用 bash disown 功能.您可以在bash中启动脚本:

You may also use bash's disown functionality. You can start a script in bash:

./execute.sh

然后按 Ctrl + z ,然后输入:

Then press Ctrl+z and then enter:

disown

该过程现在将在后台运行,与终端分离.如果您关心脚本输出,则可以将输出重定向到日志文件:

The process will now run in background, detached from the terminal. If you care about the scripts output you may redirect output to a logfile:

./execute.sh > execute.log 2>&1


另一种选择是将 screen 安装在远程计算机上,在屏幕会话中运行该命令并从中断开连接.您会发现很多有关此的教程.


Another option would be to install screen on the remote machine, run the command in a screen session and detach from it. You'll find a lot of tutorials about this.

这篇关于执行即使我注销也能运行的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆