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

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

时间2025-04-29 07:42:36分类IT科技浏览3086
导读: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
网络优化推广是什么(解锁网络推广的新境界:优化服务助您站在行业领先之巅) windows11版本22000.1(Win11 KB5023778更新推送 22621.1485预览版更新内容汇总)