1. 程式人生 > >shell獲取tomcat程序號實現必殺

shell獲取tomcat程序號實現必殺

一臺伺服器跑N多tomcat例項,根據例項名稱在apache-tomcat-7.0.56/的目錄下,看下shell指令碼,如查詢apache-tomcat-7.0.56的專案,也可以具體細化:

ps -ef | grep apache-tomcat | grep -v grep | awk '{print $2}'
  • 1

這個指令碼首先用ps -ef | grep apache-tomcat 獲得了程序資訊中包含 apache-tomcat 的程序資訊,這樣出來的結果中會包含grep本身,所以我們需要用 | grep -v grep 來排除grep本身,然後通過 awk ‘{print $2}’來打印出要找的程序。

上述例子中只是將程序id號打印出來,當然也可以修改為將tomcat程序kill掉,如下指令碼:

ps -ef | grep apache-tomcat | grep -v grep | awk '{print $2}'  | sed -e "s/^/kill -9 /g" | sh -
  • 1

版權宣告:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/u012599988/article/details/44060387