#!/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:统计文本的行数