有这样一个脚本
# !/bin/bash
while true; do
echo `date` >> ./out.txt
echo "时间 `date` 已保存"
sleep 5
done
假设这个脚本非常重要,我们要写个守护进程来保证它时刻运行
#! /bin/sh
PRO_NAME='test'
while true ; do
NUM=`ps aux | grep ${PRO_NAME} | grep -v grep |wc -l`
if [ "${NUM}" -lt "1" ];then
echo "进程重启"
nohup ./test.sh >> ./output.log &
echo "新的进程pid为:$!"
fi
sleep 3
done
exit 0