当前位置: 技术问答>linux和unix
shell脚本的问题,大家帮看下。
来源: 互联网 发布时间:2017-01-29
本文导语: ps -ef|grep -v "grep"|grep -v "dic.sh"|grep APPSVR|awk '{print $2}'|while read i do pid=$i echo 'pid=${pid}:input "y" to kill the process of APPSVR,input "n" to continue.' read oper while [[ "x"$oper != "xy" && "x"$oper != "xn" ]] do echo 'your ...
ps -ef|grep -v "grep"|grep -v "dic.sh"|grep APPSVR|awk '{print $2}'|while read i
do
pid=$i
echo 'pid=${pid}:input "y" to kill the process of APPSVR,input "n" to continue.'
read oper
while [[ "x"$oper != "xy" && "x"$oper != "xn" ]]
do
echo 'your input is error,please input "y" or "n".'
read oper
done
if [ "$oper"x = "y"x ];then
kill -15 ${pid}
if [ $? -ne 0 ]; then
echo "kill the process of APPSVR is failed."
exit
fi
fi
done
第二个read oper的时候,oper的值总是上面结果的值,我的本意是提示我输入y或者n,要不要kill这个pid。现在根本没有提示,程序一直死循环在echo 'your input is error,please input "y" or "n".'
大家帮忙看看怎解决啊。
do
pid=$i
echo 'pid=${pid}:input "y" to kill the process of APPSVR,input "n" to continue.'
read oper
while [[ "x"$oper != "xy" && "x"$oper != "xn" ]]
do
echo 'your input is error,please input "y" or "n".'
read oper
done
if [ "$oper"x = "y"x ];then
kill -15 ${pid}
if [ $? -ne 0 ]; then
echo "kill the process of APPSVR is failed."
exit
fi
fi
done
第二个read oper的时候,oper的值总是上面结果的值,我的本意是提示我输入y或者n,要不要kill这个pid。现在根本没有提示,程序一直死循环在echo 'your input is error,please input "y" or "n".'
大家帮忙看看怎解决啊。
|
第一个 read oper是浪费,因为你的初值肯定不会是y或n,能很顺利的进入那个while。试试吧
|
把第一个read oper删掉就行了。
|
linux上shell里获取pid当然是用pidof命令了。在while外面获取一次pid即可