如何在bash脚本中包含nohup?

编程入门 行业动态 更新时间:2024-10-27 14:19:35
本文介绍了如何在bash脚本中包含nohup?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个名为 mandacalc 的大型脚本,该脚本始终与 nohup 命令一起运行.如果我从命令行以以下方式调用它:

I have a large script called mandacalc which I want to always run with the nohup command. If I call it from the command line as:

nohup mandacalc &

一切迅速进行.但是,如果我尝试在命令中包含 nohup ,那么我不必每次执行时都键入它,就会收到错误消息.

everything runs swiftly. But, if I try to include nohup inside my command, so I don't need to type it everytime I execute it, I get an error message.

到目前为止,我尝试了以下选项:

So far I tried these options:

nohup ( command1 .... commandn exit 0 )

还有:

nohup bash -c " command1 .... commandn exit 0 " # and also with single quotes.

到目前为止,我只收到错误消息,抱怨有关 nohup 命令的实现或脚本中使用的其他引号.

So far I only get error messages complaining about the implementation of the nohup command, or about other quotes used inside the script.

欢呼.

推荐答案

尝试将其放在脚本的开头:

Try putting this at the beginning of your script:

#!/bin/bash case "$1" in -d|--daemon) $0 < /dev/null &> /dev/null & disown exit 0 ;; *) ;; esac # do stuff here

如果现在以--daemon作为参数启动脚本,它将重新启动与当前shell分离的脚本.

If you now start your script with --daemon as an argument, it will restart itself detached from your current shell.

您仍然可以通过不使用此选项启动脚本来在前台"运行脚本.

You can still run your script "in the foreground" by starting it without this option.

更多推荐

如何在bash脚本中包含nohup?

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

发布评论

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

>www.elefans.com

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