Linux Task Scheduler Cron

Source: Internet
Author: User


Cat/etc/crontab//configuration file for Task Scheduler
Shell=/bin/bash//define Shell variables
Path=/sbin:/bin:/usr/sbin:/usr/bin//Environment variables
Mailto=root//mailto Send mail to WHO

#For details see Mans 4 Crontabs

#Example of Job Definition:
.----------------minute (0-59)///The following five * * * * represent 5 bits, the first bit is the minute, the range is 0-59
#|.-------------Hour (0-23)//second bit is hour, range 0-23
#| |.----------Day of Month (1-31)//Third bit is date, range 1-31
#| | |.-------month (1-12) or jan,feb,mar,apr ...//fourth digit is month, range 1-12, numeric and English shorthand
#| | | |.----DAY of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat//fifth is week, 0 or 7 means Sunday, can also be written in English shorthand
#| | | | |
# user-name command to be executed//uesr-name default Root,command to be executed is required to execute
#crontab-E//Enter the crontab configuration file, using the same method as Vim, press I to enter edit mode

Instance:
There is a task schedule: 3 o'clock in the morning every day to execute the/usr/local/sbin/123.sh script, and the correct and incorrect logs are appended to the/tmp/123.log file, the specific command is as follows:
0 3 /bin/bash/usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log
Note:
denotes all meaning, the first indicates that each month's 1-31 number is executed, the second represents 1-12 months each year is executed, the third * represents every day of the week is executed, the format is: minutes + hours + days + months + weeks + specific commands

0 3 1-10 /2 /bin/bash/usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log
Note: Every year two months of 1-10 go to execute the/usr/local/sbin/123.sh script and append both the correct and the wrong log to the/tmp/123.log file

0 3 1-10 */2 2,5/bin/bash/usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log
Note: 2,5 says that as long as Tuesday and Friday go to execute
#systemctl start Crond//write a task plan cron and use the command to start the Crond service.
#ps-aux |grep cron//Check cron service has no boot

To resolve a well-written scheduled task that does not perform the method:
Either write the absolute path or write your own command to the PATH environment variable in/etc/crontab, but the surest way is to write the absolute path
Recommendation: Each write a task plan, to append the correct log and error log, so as to be able to be documented, do not perform a task scheduled to view the task execution log can be wrong

[Email protected] ~]# crontab-l
No crontab for Root
[Email protected] ~]# CRONTAB-E
Enter the following line in the task plan:
1 2 /usr/bin/find/tmp/-type f-mtime +100 |xargs rm-f//means find and delete files with/tmp/for more than 100 days
No crontab for root-using an empty one
Crontab:installing New Crontab
[[email protected] ~]# crontab-l//Use this command to view the task schedule you just added
1 2 /usr/bin/find/tmp/-type f-mtime +100 |xargs rm-f

Crontab file location path/var/spool/cron/This will have the user's cron, such as viewing the root user cron,
#cat/var/spool/cron/root
1 2 /usr/bin/find/tmp/-type f-mtime +100 |xargs rm-f//Check the result is the cron of the root user

#crontab-E//Edit task Schedule
#crontab-L//List task schedule
#crontab-r//Delete task schedule
#crontab-U root-l//Use-u to specify a user

Linux Task Scheduler Cron

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.