Linux Set timed task crontab

Source: Internet
Author: User

Linux Set timed task crontab

A period of time referring to a blog friend Git set up a timely backup of MongoDB, and later found not successful, today reconfigure a bit, the crontab of the two settings are tried, and the test can work properly.

Test machine

ubuntu14.04

1. (recommended) User-level scheduled task settings

Use the following command

crontab -e

Add a test script:

#*/1 * * * * sh ~/Desktop/myshare/cronjob.sh
#每隔一分钟执行桌面文件夹中的这个脚本

Then, update crontab

service crond restart

or use the following command, however, the system will prompt you not to recommend

/etc/init.d/crond restart
2, System-level scheduled task settings

Set/etc/crontab

#*/1 * * * * root ~/Desktop/myshare/cronjob.sh

Note System-level commands, you need to set the user name, if the system does not have root user, set other system-level user names
Once setup is complete, use the same

service crond restart

Update crontab, and then view the effects.

3, the above test script content
#!/bin/bashecho ' Hello ' >>/home/sylar/desktop/myshare/1.txtecho $ (date) >>/home/sylar/desktop/myshare/ 1.txt

The first article writes hello to file 1.txt;
The second writes the current time to 1.txt

done! The above content ensures that it can be run. For information on cron format and other cron commands, see other documentation.

Linux Set timed task crontab

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.