Linux 每小时定时任务检测程序是否死了

文件保存位置/etc/cron.hourly

此文件夹下的可执行文件会按照每小时执行一次

#!/bin/bash
if [ -z `pgrep ssserver` ]
then
        echo "not exist! restart"
        nohup /usr/bin/ssserver -c /etc/shadowsocks/config.json >/dev/null 2>&1 &
else
        echo "ssserver exist!"
fi

pgrep显示程序的PID,如果程序没有运行则返回空

shadowsocks会莫名其妙的死了,用此方法至少保证每个小时的可以检测一次比配置cron时间要简单很多。

相关推荐