在后台的bash脚本中启动下标,以便在关闭终端/ ssh会话时它仍然运行

时间:2014-11-17 13:47:03

标签: linux bash

我正在尝试编写一个简单的bash脚本,该脚本应该以另一个用户身份启动另一个脚本并以某种方式启动脚本

  1. 当我关闭主脚本时仍然运行
  2. 当我关闭终端或ssh会话时仍然运行
  3. 可以通过简单调用另一个脚本来停止。
  4. 我现在拥有的:

    这基本上是start.sh的样子

    # doing some other stuff
    sudo su user_the_script_should_start_as -c "./start-in-background.sh $1 $2 $3"
    

    启动在背景-SH

    # doing some other stuff
    # Start other Script in Background
    

    我怎么能做到这三点?

1 个答案:

答案 0 :(得分:0)

您可以使用

nohup bash your_script.sh &

disown bash your_script.sh &

screen

但我的建议是screen命令。 tumx也很好用。

对于您最后一次停止脚本调用的要求,可以通过以下命令

来实现
kill $!
相关问题