执行即使我注销也能运行的脚本

编程入门 行业动态 更新时间:2024-10-10 21:26:17
本文介绍了执行即使我注销也能运行的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

因此,我有一个运行时间很长的脚本(大约几天),说 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.

更多推荐

执行即使我注销也能运行的脚本

本文发布于:2023-11-23 13:25:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621603.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:也能   使我   脚本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!