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
shell執行的目的是根據我輸入的字串找到對應的行程殺死
這樣執行時回傳結果為
[root@localhost new]# sh deploy1.sh -M asfasfa
line:26
但是如果我找自己運行的程式時,此時程式還未運行,但還是獲取到了未知的pid
[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]# 這是什么原因引起的呢?
uj5u.com熱心網友回復:
頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂uj5u.com熱心網友回復:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/276850.html
標籤:系統維護與使用區
上一篇:求一個arm版本的linux,可以在電腦上或者虛擬機上暗轉,謝謝,急!!!
下一篇:求問 Ubuntu
