In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
I'm going to write a shell script on the springboard machine that will batch check that the main process on the remote server is running healthily.
First find one of the remote machines and see how the main process works
[root@two002 tmp]# ps -ef|grep mainroot 23448 23422 0 11:40 pts/0 00:00:00 grep --color=auto main [root@two002 tmp]# ps -ef|grep main|grep -v grep|wc -l
The shell check script is as follows
[root@two002 tmp]# cat /tmp/main_check.sh#!/ bin/bashNUM=$(ps -ef|grep main|grep -v grep|wc -l)if [ $NUM -eq 0 ];then echo "It's not good! main is stoped! "else echo "Don't worry! main is running! "fi
execute scripts
[root@two002 tmp]# sh -x /tmp/main_check.sh++ grep main++ grep -v grep++ wc -l++ ps -ef+ NUM=2+ '[' 2 -eq 0 ']'+ echo 'Don'\''t worry! main is running! 'Don't worry! main is running! [root@two002 tmp]# sh /tmp/main_check.shDon't worry! main is running!
As a result of the above execution, it is found that during the script execution process, the result value assigned to the NUM parameter is 2! But manually execute ps -ef| grep main| grep -v grep| Wc -1 is 0!
This is due to the problem of grep matching, which requires grep to match exactly, i.e."grep -w." This requires modifying the main_check.sh script as follows:
[root@two002 tmp]# cat /tmp/main_check.sh#!/ bin/bashNUM=$(ps -ef|grep -w main|grep -v grep|wc -l)if [ $NUM -eq 0 ];then echo "Oh! My God! It's broken! main is stoped! "else echo "Don't worry! main is running! "fi
Run the check script again and it's OK.
[root@two002 tmp]# sh -x /tmp/main_check.sh++ grep -w main++ grep -v grep++ wc -l++ ps -ef+ NUM=0+ '[' 0 -eq 0 ']'+ echo 'Oh! My God! It'\''s broken! main is stoped! 'Oh! My God! It's broken! main is stoped! [root@two002 tmp]# sh /tmp/main_check.shOh! My God! It's broken! main is stoped!
Therefore, on the springboard machine, the script for batch checking the running status of the main process of the remote server is:
[root@tiaoban ~]# cat /usr/bin/main_check#!/ bin/bashNUM=$(ps -ef|grep -w main|grep -v grep|wc -l)if [ $NUM -eq 0 ];then echo "Oh! My God! It's broken! main is stoped! "else echo "Don't worry! main is running! "fi [root@tiaoban ~]# cat /opt/script/main_check.sh#!/ bin/bash for i in $(cat /opt/ip.list)do/usr/bin/rsync -e "ssh -p22" -avpgolr /usr/bin/main_check $i:/usr/bin/ > /dev/null 2>&1ssh -p22 root@$i "echo $i;sh /usr/bin/main_check"done
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.