Instructions on shell programming and cron scheduled tasks

Source: Internet
Author: User
For more information about shell programming and cron planning tasks-Linux general technology-Linux programming and kernel, see the following. Recently, a server encountered a problem (the specific cause has not been identified. The initial diagnosis is that the php load is too high, leading to network congestion, and eventually the network crashes and cannot access the Internet. This is an out-of-the-box question. it has nothing to do with this topic. in this case, the server is disconnected from the network and cannot connect to the network. you can run the service network restart command to restart the network service.
Therefore, I wrote a script to check the network every two minutes. when the Gateway cannot be pinged, the network disconnection log is recorded and the network service (service network restart) is restarted ), ping rules only record logs.
Now the problem is that if you manually run the script, you can perform normal detection and record operations, or you can restart the network service if the network is disconnected. However, after you add the script to a scheduled task, everything is fine, only the key service network restart cannot take effect! (The log has a network disconnection record)


Attach the script. please advise!


1 #! /Bin/sh
2 ping-c 1 192.168.255.254>/root/check/res
3 grep ttl/root/check/res>/root/check/rus
4 if ['WC-l/root/check/rus | awk' {print $1} ''= 0]
5 then
6 date>/root/check/off_log
7 echo "offline! ">>/ Root/check/off_log
8 service network restart>/root/check/off_log
9 else
10 date>/root/check/log
11 echo "online">/root/check/log
12 fi


The script is relatively simple and will not be explained. The key is row 8. I want to output the running result to the off_log file. However, I only view the off_log with the offline record. I have not restarted the network service, and I have not restarted the network service!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.