vim monitorProcess.sh
#!/bin/bash
if [ ! "$1" ]
then
echo "please input the process key as a argc"
exit
else
ps -elf| grep $1 | grep -v grep > /dev/null
if [ $? -ne 0 ]
then
echo " the $1 is not running,starting it "
else
echo "the $1 is running"
fi
fi
使用方法
sh monitorprocess.sh 进程关键字
几个注意点:
1. 判断参数是否为空 !$1
2.判断进程是否存在
ps -elf | grep processkey| grep -v grep
这里有个grep -v
3. if then else fi结构