Ubuntu12.04Servercron timed monitoring

Source: Internet
Author: User
The cron service is installed by default on Ubuntu12.04server. You can use the crontab-e command to bring up the default editor in your system to edit the crontab command format. For details, refer to the following article.

The cron service is installed by default on Ubuntu12.04 server. You can use the crontab-e command to bring up the default editor in your system for editing.

Crontab command format can refer to the following article, very good: http://www.linuxidc.com/Linux/2007-09/7681.htm and http://www.linuxidc.com/Linux/2012-08/67836.htm

My requirement is that the nginx service has been installed in the system. The start command is service nginx start.

Due to nginx's stability, I chose a scheduled task for checking every minute:

*/1 *****/home/dist/monitor/nginx_watcher.sh

*/1 indicates running once a minute

Others * indicates no settings

My script file is as follows:

  1. File Edit Options Buffers Tools Sh-script Help
  2. #! /Bin/bash
  3. # PATH =/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
  4. Pid_file =/usr/nginx/logs/nginx. pid
  5. Log_file =/home/dist/monitor/watcher. log
  6. If[! -F $ pid_file]; then
  7. Echo "----------------"> $ log_file
  8. Echo 'date'> $ log_file
  9. Echo "nginx is found stopped, restaring it now"> $ log_file
  10. Echo "----------------"> $ log_file
  11. Service nginx start
  12. Fi

Check whether the nginx process id file exists to determine whether nginx is running. If not, call the service nginx start command.

Notes:

1. Execute crontab-e with the root permission.

2. If you do not have to worry about setting a scheduled task, run the following command to restart the cron service. In my experience, I don't have.

Service cron restart

3. If you want to ensure that the PATH of the environment variable is correct, you can set the PATH of the environment variable in your own script, and then export it out.

4. Use absolute path for file paths

5. The following scheduled tasks can help us diagnose the environment variables of the cron service:

* ***** Env>/tmp/env. output

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.