Teach you crontab barrier

Source: Internet
Author: User

Guide Crond is a daemon that is used to periodically perform certain tasks or wait for certain events under Linux, similar to Scheduled tasks under Windows, when the operating system is installed, the Service tool is installed by default and the Crond process is started automatically. The Crond process periodically checks to see if there is a task to perform and automatically executes the task if there are tasks to perform. The task scheduling under Linux is divided into two categories, system task scheduling and user task scheduling. System task scheduling: The work to be performed by the system periodically, such as writing cache data to hard disk, log cleanup, etc. In the/etc directory there is a crontab file, this is the System Task Scheduler configuration file.

crontab configuration file
shell=/bin/bashpath=/sbin:/bin:/usr/sbin:/usr/binmailto=roothome=/#. —————-minute (0–59) # |. ————-hour (0–23) # | | . ———-Day of Month (1–31) # | | |. ——-month (1–12) OR jan,feb,mar,apr ... # | | | |--Day of Week (0–6) (sunday=0 OR 7) or#sun,mon,tue,wed,thu,fri,sat# | | | | |# m h DOM Mon Dow command# * * * * * command'll be executed

For example:

*/5 * * * * Root/usr/libexec/atrun

Minute (m): Represents the first part of an hour, the range 0-59. Hour (h): Represents the first hour of the day, in scope 0-23. Mday (DOM): Represents the day of the one month, the range 1-31. Month (Mon): Represents the month ordinal of a year, with a range of 1-12. Wday (DOW): On behalf of the day of the week, the range 0-7 (0 and 7 are Sunday). Who: To use what identity to execute the directive, when you use CRONTAB-E, you do not have to add this field. Command: The command to execute.

Crond boot up Crond Startup/shutdown Scripts
/etc/init.d/crond helpusage:/etc/init.d/crond {start|stop|status|restart|condrestart|try-restart|reload| Force-reload}
Crond join to boot boot
Chkconfig Crond on

Crontab Scheduled Tasks do not perform a problem

crontab Scheduled Tasks do not perform a problem

The reasons for troubleshooting are as follows: first, confirm that the server is enabled for scheduled task scheduling service and only the root user can open and close the Crond service

[[Email protected] script]# service Crond Statuscrond is stopped[[email protected] script]# service Crond startstarting CR Ond: [OK][[email protected] script]# service Crond statuscrond (PID 24577) is running ...

Make sure the Crond status is running ... If the Crond status is stopped, then the scheduled task service does not take effect and cannot be executed, and the crontab I encounter is the reason why

Several problems of crontab common mistakes

Edit crontab:

crontab-e# m H Dom Mon Dow commandshell=/bin/bash30 * * * * cd/home/barry/top800/top10/top10_fruits/&&/top10_ all.sh

CTRL + O (write)-"Enter" (save file name)--"Ctrl + X (exit) Enter the view command:

crontab-l# m H Dom Mon Dow commandshell=/bin/bash30 * * * * cd/home/barry/top800/top10/top10_fruits/&&/top10_ All.sh (recommended in this way)
If you encounter a shell syntax error
Syntax Error: "(" unexpected

WORKAROUND: You need to specify the Shell interpreter command: Shell=/bin/bash (see crontab editing example Shell=/bin/bash above) or see: Linux–bash Syntax Error

If you encounter a path error

In/var/spool/crontab/yanggang, the following command was added, prompting for the xxx.sh path not found in the log file/var/spool/mail/yanggang

* * * * */home/barry/top800/top10/top10_fruits/top10_all.sh

Or

* * * * * bash/home/barry/top800/top10/top10_fruits/top10_all.sh

This is because you use an absolute path to execute script top10_all.sh in crontab, so other scripts referenced in script top10_all.sh need to use absolute paths to be crontab found and executed. So how to avoid the absolute path, it is recommended to use the following format:

* * * * * cd/home/barry/top800/top10/top10_fruits/&&/top10_all.sh (recommended in this way)

Enter the directory first, and then execute the script; otherwise, the execution of other scripts in the script will need to add an absolute path

Originally from: http://www.linuxprobe.com/crontab-tshoot.html

Free to provide the latest Linux technology tutorials Books, for open-source technology enthusiasts to do more and better: http://www.linuxprobe.com/

Teach you crontab barrier

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.