Ubuntu uses crontab for scheduled tasks

Source: Internet
Author: User
Since the server migration, the custom code Warehouse backup script has never been executed, but the environment of the original machine does not exist and you can only find it yourself. Although I know that cron is used to implement scheduled tasks, I still don't know how to do it. Today I finally got the result. The following is my implementation method (Environment Ubuntu8.04 ). 1. The use of the crontab-e command is relatively simple. Enter directly ~ # Crontab-e will open an editing window. The first line will contain the content format prompt :#

Since the server migration, the custom code Warehouse backup script has never been executed, but the environment of the original machine does not exist and you can only find it yourself. Although I know that cron is used to implement scheduled tasks, I still don't know how to do it. Today I finally came up with the result. The following is my implementation method (Environment Ubuntu 8.04 ).

1. Use the crontab-e command

This command is easy to use. Enter directly

~ # Crontab-e

An editing window will be opened. The first line will show the content format prompt:

# M h dom mon dow command
Specific meaning: minute Hour Date month week command, in a month (mon) One day (dom) or the day of the week (dow) (h, 24 hours) A minute (m) executes a command, * indicates any time. For example:

3 ***/home/meng/hello. sh

That is, execute the hello. sh script under/home/meng/at 03 every hour.

After saving the file, press Ctrl + X at the bottom of the screen to exit. The system prompts whether to save the file and enter Y. The system prompts you to enter the file name and a temporary file name. Because it is only a test, press enter to save the settings.

Note: After editing, restart the cron process:

~ #/Etc/init. d/cron restart

Observe the running result and you will find that hello. sh is executed every hour.

When using this command, the biggest concern is whether the command can be successfully executed after the system is restarted? After I restarted the system, I found everything was normal, so I dispelled this concern. However, there is still a problem. Generally, the server is logged on after restart, and no user logs in. If I am not using the root account when executing the crontab-e command, will the system be successfully executed after the system is restarted?

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.