2020-10-02Linux shell judges whether the url can be accessed, and restarts if there is a problem when visiting the website regularly, so I don’t bother to check the fault

#网站守护
testurl='http://wjsou.com'
status=$(curl -s -m 5 -IL $testurl|grep 200)
if [ "$status" == "" ]
then
	echo $(date)$testurl' is OFF'>>/root/log_wjsou_off.txt
	reboot
fi

#采集进程守护
rownum=$(jps |grep BaiduEngine4 |wc -l)
if [ $rownum != 1 ]
then
	echo $(date)"BaiduEngine4 $rownum">>/root/log_wjsou_off.txt
	kill -9 `jps | grep BaiduEngine4 | awk '{print $1}'`
	rm -rf /root/Myfile.txt
	nohup java -jar /root/BaiduEngine4.jar >/dev/null 2>&1 &
fi

curl -s -m 5 -IL'http://www.baidu.com'|grep 200
-s silent mode, the progress bar and error message are not displayed.
-m max-time, the maximum time for this request. 5 seconds.
-I curl only judges the parameters of the response header information
-L allows jump
|grep Whether a certain string is included in the output of a command. For example, ls |grep 200 is used to search the output after the ls command is executed, whether it contains 200

 

|awk'{print $1}' is divided by blanks to display the first paragraph of the text
|wc -l only output the number of lines of files or content
|grep -v exclude certain fields. For example, cat test.log | grep "login"|grep -v "deviceType" finds out the test.log contains login information and does not have the deviceType field
|grep -w matches all words

jps (Java Virtual Machine Process Status Tool) is a command provided by java to display the pids of all the current java processes

Guess you like

Origin blog.csdn.net/chenhao0568/article/details/108899849