#!/bin/bash
while [ 1 ]
do
process_is_exstit=$(ps -ef | grep "yourProcess" | grep -v grep | wc -l)
if [ ${process_is_exstit} == 0 ]
then
echo '程序重啓中'
sleep 300
#enter your execute command
#...
fi
date
echo 'running'
sleep 120
done
主要學習
ps的兩個參數:
-e:列出所有的進程
-f:全格式輸出
grep -v grep:
-v 表示反選,匹配不包含關鍵詞的內容
wc -l:
-l:統計文本的行數