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