这个
#!/bin/bash
if [ `ps -ef | grep "91.34.124.35" | grep -v grep | wc -l` -eq 0 ]; then sh home/asfd.sh; fi
或这个?
ps -ef | grep "91\.34\.124\.35" | grep -v grep > /dev/null
if [ "$?" -ne "0" ]
then
sh home/asfd.sh
else
echo "Process is running fine"
fi
您好,如何编写一个查看正在运行的进程的shell脚本,如果没有进程名称CONTAINING 91.34.124.35,那么在某个地方执行一个文件,我想在连续循环中每隔30秒运行一次,我觉得有一个睡眠命令.
解决方法:
你不能使用cron因为我知道最小的单位是一分钟.您可以使用sleep但是您的进程将始终运行(使用cron它将每次启动).
只是睡觉
while true ; do
if ! pgrep -f '91\.34\.124\.35' > /dev/null ; then
sh /home/asfd.sh
fi
sleep 30
done
如果你的pgrep有选项-q来抑制输出(如在BSD上),你也可以使用pgrep -q而不将输出重定向到/ dev / null
标签:linux,shell
来源: https://codeday.me/bug/20191007/1865164.html