19,612
社区成员
发帖
与我相关
我的任务
分享
while getopts ":M:" opt
do
case $opt in
M)
MAINCLASS=$OPTARG
;;
?)
echo "Illegal option,please read README.md"
exit 1;;
esac
done
MAINCLASS=com.test.auto.main.AutoMain
PROJECTNAME=test_auto_main
stopByName(){
#Get project PID
# if [ $PROJECTTYPE = class ];then
# STOPNAME=$MAINCLASS
# elif [ $PROJECTTYPE = jar ] || [ $PROJECTTYPE = main ];then
# STOPNAME=$PROJECTNAME
# else
# echo line:$LINENO illegal paramter
# fi
# echo $STOPNAME
current_pid=$( ps -ef|grep $MAINCLASS |grep -v grep | awk '{print $2}' | awk -F"/" '{ print $1 }' )
echo line:$LINENO $current_pid
if [ $current_pid ];then
echo Now the application is running, close the application first
#This is the easiest way to stop a project. If there is a better way to stop a project, it can be changed
kill -9 $current_pid
fi
}
stopByName
[root@localhost new]# sh deploy1.sh -M asfasfa
line:26
[root@localhost new]# sh deploy1.sh -M com.test.auto.main.AutoMain
line:26 24685 24686
deploy1.sh: line 27: [: 24685: unary operator expected
[root@localhost new]# ps -ef|grep com.test.auto.main.AutoMain |grep -v grep | awk '{print $2}' | awk -F"/" '{ print $1 }'
[root@localhost new]#
while getopts ":p:o:s:hH:m:j:t:l:L:P:n:O:S:M:a:" opt
do
case $opt in
M)
M=$OPTARG
;;
?)
echo "Illegal option,please read README.md"
exit 1;;
esac
done
#MAINCLASS=com.test.auto.main.AutoMain
echo $M
current_pid=$( ps -ef|grep $M |grep -v grep | awk '{print $2}' | awk -F"/" '{ print $1 }' )
echo line:$LINENO $current_pid
我整理了一下代码,发现只要字符串从外面指定并生效,就一定会出现此问题
[root@xd-vdn-liveback-01 yuewendong]# sh deploy3.sh -M aasgsdgsr
aasgsdgsr
line:16 5593 5594