linux脚本练习(一):判断进程是否存在
vim monitorProcess.sh#!/bin/bashif [ !"$1" ]thenecho "please input the process key as a argc"exitelseps -elf| grep $1 | grep -v grep > /dev/nullif [$? -ne...
·
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结构
更多推荐
已为社区贡献1条内容
所有评论(0)