如何在 Linux 的后台运行脚本.- 外壳脚本 [英] How to run a script in background in Linux. - shell scripting

查看:50
本文介绍了如何在 Linux 的后台运行脚本.- 外壳脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个不断更新日志文件的脚本.诸如系统时间和日期、当前登录的用户等数据,每隔一段时间(例如 5 分钟).即使在终端关闭后,脚本也必须运行.

A script that keeps updating the log file. data like system time and date, users currently logged in etc for every interval of time say 5 minutes. THE SCRIPT MUST RUN EVEN AFTER THE TERMINAL HAS BEEN CLOSED.

推荐答案

实际上,没有.首先,你不需要 sh:

Actually, no. First of, you don't need sh:

$ ./newscript.sh &

这就够了.这将启动一个后台进程.但是您的终端仍在控制它.要实现您想要的行为,请执行以下操作:

This is enough. This will start a background process. But your terminal is still controlling it. To achieve the behavior you want, do this:

$ disown %1

这将否认带有 jobspec 1(类似于 id)的作业,这是您事先启动的.现在您可以关闭终端了.

This will disown the job with the jobspec 1 (which is like an id), which was the one you started beforehand. Now you can close the terminal.

这篇关于如何在 Linux 的后台运行脚本.- 外壳脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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