首页IT科技shell判断脚本是否执行成功(shell:判断一个进程是否存在)

shell判断脚本是否执行成功(shell:判断一个进程是否存在)

时间2025-06-20 05:16:35分类IT科技浏览4294
导读:Javascript代码 #test.sh #!/bin/sh pid=`ps-ef|grep-vgrep|grep-v"test.sh...

Javascript代码
#test.sh #!/bin/sh pid=`ps-ef|grep-vgrep|grep-v"test.sh"|grep$1|sed-n1P|awk{print$2}` if[-z$pid];then echo"nothisprocess" else echo$pid fi

#test.sh<br /> #!/bin/sh<br /> pid=`ps -ef | grep -v grep | grep -v "test.sh" | grep $1 | sed -n 1P | awk {print $2}`<br /> if [ -z $pid ] ; then<br /> echo "no this process"<br /> else<br /> echo $pid<br /> fi

例:
查询是否存在hello进程
#./test.sh hello
如果存在hello进程            ,会输出PID
不存在会输出 no this process

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
python 魔术命令(Python魔术方法的三个特点)