标签:
报错:
/usr/local/bin/stop.sh: line 3: [: 2151: unary operator expected
原因:
shell脚本名字叫stop_tomcat.sh,永远不会执行else
因为脚本本身包含tomcat,shell脚本能查到stop_tomcat这条进程
即第一个grep后的内容(tomcat)不唯一,会查到多个pid
#!/bin/bash #shell脚本中第一行必须写
pid=`ps -ef|grep tomcat|grep -v grep|awk ‘{print $2}‘`
if [ $pid ]
then
kill -9 $pid
echo ‘mysql is stopped...‘
else
echo "mysql is not running..."
fi
解决办法:
脚本做如下改动,路径是唯一的
#!/bin/bash shell脚本中第一行必须写
pid=`ps -ef|grep /usr/local/tomcat_fcx|grep -v grep|awk ‘{print $2}‘`
if [ $pid ]
then
kill -9 $pid
echo ‘mysql is stopped...‘
else
echo "mysql is not running..."
fi
linux-制作shell脚本在任何路径下用自定义命令关闭tomcat-pid不唯一的问题
标签:
原文地址:http://www.cnblogs.com/fucaixia598/p/5922582.html