《Shell编程实例 —— 后台检测应用程序运行》
1.守护脚本
一般用来检测项目中程序是否奔溃退出,以及程序重启多次后直接重启整个机器。
#!/bin/sh yd_media_app & count=0 while true do stillRunning=$(ps | grep "yd_media_app" | grep -v "grep") if [ -z "$stillRunning" ]; then echo "yd_media_app not running, restart" if [ $count -eq 0 ]; then start_time=$(date +%s) elif [ $count -eq 3 ]; then end_time=$(date +%s) cost_time=$((end_time-start_time)) echo "cost_time:"$cost_time if [ $cost_time -lt 60 ]; then reboot fi fi count=$((count+1)) yd_media_app & fi sleep 1 done
浙公网安备 33010602011771号