Linux shell scripts that safely kill Tomcat processes, as many good script programming skills are used in this script, I would like to share with you;
#
# Firstly find the process of the tomcat ....
Tomcat_process_str = 'ps aux | grep 'java. * Tomcat '| grep-V grep'
Process_array = ($ {tomcat_process_str ///})
Tomcat_process_id =_id {process_array [1]}
Echo $ tomcat_process_id
#
# Secondly send stop tomcat to see if we can kill it
Stoptomcat
Sleep 12
#
# Last we'll use kill Tomcat process in a looking up Loop
For (a = 1; A <= 100; A ++ ))
Do
Check_str_length = 0
Tomcat_process_check_str = 'ps aux | grep 'java. * Tomcat '| grep-V grep'
Check_str_length =$ {# tomcat_process_check_str}
If [$ check_str_length! = 0]
Then
Kill $ tomcat_process_id
Sleep 5
Echo try to kill Tomcat once more...
Else
Echo Tomcat is already killed
Break
Fi
Done
It is particularly worth mentioning that:
Tomcat_process_str = 'ps aux | grep 'java. * Tomcat '| grep-V grep'
Using two grep operations to remove the interference of grep processes on search results is very skillful.