Ubuntu 12.04 server cron timed monitoring

Source: Internet
Author: User

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.

For the crontab command format, refer to the following article, which is very good:

Http://blog.csdn.net/love__coder/article/details/6890997

The Ubuntu site also provides the following manuals:

Http://wiki.ubuntu.org.cn/CronHowto

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:

File Edit Options Buffers Tools Sh-Script Help                                                                                                                                                                       #! /bin/bash                                                                                                                                                                                                         #PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games                                                                                                                                        pid_file=/usr/nginx/logs/nginx.pidlog_file=/home/dist/monitor/watcher.logif [ ! -f $pid_file ]; then    echo "----------------" >> $log_file    echo `date` >> $log_file    echo "nginx is found stopped, restaring it now" >> $log_file    echo "----------------" >> $log_file    service nginx startfi

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.