今天寫了個es安裝腳本,腳本安裝過程中,需要重啟es。
需求就是,根據es端口號,查到對應的pid,根據pid將進程殺死,然后重啟。
shell中通過端口號查詢pid
esPort=8080
#根據端口號查詢對應的pid
pid=$(netstat -nlp|grep :$esPort|awk '{print $7}'|awk -F"/" '{ print $1 }');
#殺掉對應的進程,如果pid不存在,則不執行
if [ -n "$pid" ]; then
kill -9 $pid;
fi
