Home > OS >  For help, to capture the process id in the shell, can get pid to simply does not exist, don't k
For help, to capture the process id in the shell, can get pid to simply does not exist, don't k

Time:04-17

 while getopts ": M:" opt 
Do
Case $opt in
M)
MAINCLASS=$OPTARG
;;
?).
Echo "Illegal option, both please read the README, md,"
1; exit;
Esac
The 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
# the 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 ')
The 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 execution according to the input string I find is the purpose of the corresponding process to kill

Such execution returns results for
 [root @ localhost new] # sh deploy1. Sh -m asfasfa 
The line: 26


But if I find myself running program, this program is not running, but I still get to the unknown pid
 [root @ localhost new] # sh deploy1. Sh - M com test. Auto. Main. AutoMain 
The line: 26, 24685, 24686
Deploy1. Sh: line 27: [: 24685: unary operator expected


Execute the following command, you can see that my program is not running
 [root @ localhost new] # ps - ef | grep com. Test. Auto. Main. AutoMain | grep -v grep | awk '{print $2}' | awk -f "/" '{print $1} 
[root @ localhost new] #



What is the cause?

CodePudding user response:

By bumps bumps bumps bumps bumps bumps bumps bumps bumps bumps bumps bumps bumps bumps

CodePudding user response:

 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, both please read the README, md,"
1; exit;
Esac
The 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 ')
The echo line: $LINENO $current_pid


I adjusted the code, I found, as long as the string from the specified outside will appear this problem
 [root @ xd - VDN - liveback - 01 yuewendong] # sh deploy3. Sh -m aasgsdgsr 

Aasgsdgsr

The line: 16, 5593, 5594
  • Related