shell script out the process according to the port number kill

Assuming a scenario, under certain circumstances, we need to close an application process, and then re-start the deployment . Not the same scenario requires the use of different scripts, such as when using the tomcat, and by start.up.sh shutdown.sh to operate, but it seems there is no other good way, so uses a PID kill off the application, and then re-start the deployment. However, every time you start the PID is not the same, but we know that every start times will be the same port number, if the query to the application by the port number PID to go kill off, it will save a lot.

Then you can query through the port in the shell PID

= Port 8030 
# query according to the port number corresponding to the PID 
PID = $ (-nlp the netstat | grep : Port $ | awk  ' {}. 7 Print $ ' | awk -F " / "  ' {}. 1 Print $ ' ); 

# kill If PID corresponding process is not present, i.e., the port is not open, is not performed 
IF [-n   " $ PID " ]; the then 
    the kill   - . 9   $ PID;
 Fi

This can be achieved run the shell script in a production environment to stop the specified service port, and a key to start.

Note that this script is best to write directly on linux, or will go wrong, will report a variety of errors, specific errors we can go on their own Baidu resolve many of the Internet.

 

Guess you like

Origin www.cnblogs.com/f-g-f/p/11488607.html