我创建了一个非常简单的脚本,名为main_start_script,它将在后台运行2个python程序,代码为:
python /opt/cuckoo/cuckoo-2/cuckoo.py 1>cuckoo_script/cuckoo_start.txt 2>&1 &
python /opt/cuckoo/cuckoo-2/utils/web.py 1>cuckoo_script/web_start.txt 2>&1 &
现在我想知道如何检查这两个程序是否正在运行,如果没有,请运行脚本启动它们.
我听说人们建议使用“Puppet”进行检查,但到目前为止我还没有找到有用的教程.
解决方法:
comman pgrep -f< file>将返回指定文件的当前实例数.例如:
[user@localhost ~]$pgrep -f /sbin/init
1
[user@localhost ~]$
如果文件未与进程关联,它将不返回任何内容.
这可以合并到一个bash脚本中,如果脚本尚未运行,它将执行该脚本:
#!/bin/bash
if [[ ! $(pgrep -f script.sh) ]]; then
script.sh
fi
标签:python,linux,puppet,background-process,process-management
来源: https://codeday.me/bug/20190816/1666726.html