欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

shell腳本如何查詢進程并殺死

 更新時間:2023年07月18日 15:48:15   作者:qq759035366  
工作中經常需要寫一個定時腳本,需要找到一個進程,然后殺死,并定時重新啟動這個進程,這篇文章主要介紹了shell腳本查詢進程并殺死,需要的朋友可以參考下

shell腳本查詢進程并殺死

說明:
工作中經常需要寫一個定時腳本,需要找到一個進程,然后殺死,并定時重新啟動這個進程。

具體腳本如下:(ngsp代表是什么進程)

#!/bin/bash
ID=`ps -ef | grep ngsp | grep -v grep | awk '{print $2}'`
echo $ID
for id in $ID
do
kill -9 $id
echo "kill $id"
done

或者有些朋友看了,不明白,我這里就舉一個httpd的例子吧

1. 安裝一個apache服務

yum -y install httpd
systemctl start httpd

在這里插入圖片描述

網(wǎng)頁訪問:IP:80 比如1.117.92.32:80 看到網(wǎng)頁說明httpd部署成功了。

在這里插入圖片描述

查看httpd的服務:

在這里插入圖片描述

如下是腳本殺死進程和啟動腳本

[root@VM-4-11-centos ~]# ls
kill_httpd.sh  start_httpd.sh
[root@VM-4-11-centos ~]# cat kill_httpd.sh 
#!/bin/bash
ID=`ps -ef | grep httpd | grep -v grep | awk '{print $2}'`
echo $ID
for id in $ID
do
kill -9 $id
echo "kill $id"
done
[root@VM-4-11-centos ~]# cat start_httpd.sh 
#!/bin/bash
systemctl start httpd
[root@VM-4-11-centos ~]# 

設置定時啟動腳本:crontab -e進行編輯

[root@VM-4-11-centos ~]# crontab -l #查看定時任務,我的腳本在 /root/路徑下,我這是每天10點50運行殺死進程,然后每天10點52重新啟動httpd服務
*/5 * * * * flock -xn /tmp/stargate.lock -c '/usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &'
50 10 * * * /root/kill_httpd.sh
52 10 * * * /root/start_httpd.sh
[root@VM-4-11-centos ~]# 

到此這篇關于shell腳本查詢進程并殺死的文章就介紹到這了,更多相關shell查詢進程并殺死內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論