Planning tasks for Linux systems
Linux system Operations Engineers most of the management work is done by automatically executing a script on a regular basis.
Cron function is very important, remember!!!
Planning function Crontab:
-U: (user) indicates that a user is specified and no-U is the current user
-E: Indicates that a scheduled task is specified
-L: (list) indicates a scheduled task is listed
-R: (remove) to delete scheduled tasks
#crontab-e01 3 echo "OK" >/root/cron.log
Command explanation: Write a task plan that actually uses VIM to open the crontab configuration file
01 10 05 06 3 in turn, "time-sharing Week" command line
As indicated on June 5 (must be Wednesday) 10:01 perform echo "OK" >/root/cron.log
Crontab-e actually open a/var/spool/cron/username file
If the user is root, open the /var/spool/cron/root
★ Note: Do not use vim directly to edit, will be wrong, must use CRONTAB-E to edit
View the Scheduled Tasks
#crontab-L
Delete a scheduled task
#crontab-R
Crontab Exercises
-
-
14th per month, 4:10 "/bin/sh/usr/local/sbin/ backup_month.sh "
-
execute every 8 hours ntpdate time.windows.com "
-
-
"/bin/sh/usr/local/sbin/test2.sh"
at 9 to 18 O ' Day
exercise answer:
1. 20 1 * * * echo "" >/var/log/slow.log
2. 0 3 * * 0 /bin/sh /usr/local/sbin/backup.sh
3. 10 4 14 * * /bin/sh /usr/local/sbin/backup_month.sh
4. 0 */8 * * * ntpdate time.windows.com
5. 0 1,12,18 * * * /bin/sh /usr/local/sbin/test.sh
6. 0 9-18 * * * /bin/sh /usr/local/sbin/test2.sh
Every 8 hours, is to use all the hours (0-23) to remove 8, think about the results, in fact, it should be 0,8,16 three number.
When encountering multiple numbers (minutes, hours, months, weeks) such as the 5th question, you need to separate them with commas.
and the time period can be used n-m
, as in the sixth question (9-18).
After all the scheduled tasks are set up, you need to check to see if the Crond service is started:
#service crond Status
If it is a stop state, you need to start it:
#service Crond Start
This article is from the "Old seven Linux Operations Management" blog, please be sure to keep this source http://asd9577.blog.51cto.com/4291946/1930304
Task Scheduler for Linux Systems