"Turn" crontab detailed

Source: Internet
Author: User
Tags crontab example

Original link http://hougbin.iteye.com/blog/799335

Crontab detailed cron is a daemon that can be used to schedule execution of repetitive tasks based on a combination of time, date, month, and week. Cron assumes that the system is running continuously. If the system is not running when a task is scheduled, the task will not be executed. To use the Cron service, you must have Vixie installed-cron RPM Package and must be running the Crond service.
To determine if the package is installed, use the Rpm-q vixie-cron command. To determine whether the service is running,
Using/sbin/Service crond Status command. 37.1.1Configuration cron Task Cron main profile is/etc/crontab, which includes the following lines: SHELL=/bin/Bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=Root HOME=/# Run-Parts on* * * * Root run-parts/etc/cron.hourly Geneva 4* * * Root run-parts/etc/cron.daily A 4* *0Root run-parts/etc/cron.weekly the 4 1* * Root run-parts/etc/cron.monthly The first four rows are variables that you can use to configure the Cron task runtime environment. The value of the shell variable tells the system which shell environment to use (in this case, the bash shell);
The path variable defines the paths used to execute the command. The output of the cron task is mailed to the user name defined by the MAILTO variable.
If the MAILTO variable is defined as a blank string (MAILTO=""), the email will not be sent out. The home variable can be used to set the home directory to use when executing a command or script. /etc/each line in the Crontab file represents a task in the format: Minute hour day month DayOfWeek command minute- Minutes, from0To -any integer between hour-hours, from0To atany integer between the day-date, from1To toany integer between (if a month is specified, it must be a valid date for that month) month-month, from1To Aany integer between (or using the English abbreviation of the month such as Jan, Feb, etc.) dayofweek-week, from0To7Between any integers, here's the0Or7represent Sunday (or use the English abbreviations of the week such as Sun, Mon, etc.) command-the command to execute (the command can be LS/proc >>/tmp/commands such as proc can also be commands that execute scripts that you write yourself. ) in any of the above values, the asterisk (*) can be used to represent all valid values. For example, an asterisk in a month value means that the command is executed monthly after other constraints have been met. A short line between integers (-) to specify an integer range. Such as1-4means an integer1、2、3、4. Specify a list with a series of values separated by commas (,). For example,3,4,6,8indicate these four specified integers. Forward slash (/) can be used to specify the interval frequency. Adding/<integer> after a range means that integers can be skipped within the range.
Such as0- -/2Can be used to define every two minutes in the Minutes field. The interval frequency value can also be used with asterisks.
For example, */3The value can be used in the month field to indicate that the task runs every three months. The line starting with the pound sign (#) is a comment and will not be processed. If you areAs seen in the/etc/crontab file, it uses Run-parts scripts to perform/etc/cron.hourly,/etc/cron.daily,
/etc/cron.weekly and/etc/The scripts in the Cron.monthly directory, which are executed hourly, daily, weekly, or monthly.
The files in these directories should be shell scripts. If a cron task needs to be executed according to the schedule instead of hourly, daily, weekly, or monthly execution, it can be added to theThe/ETC/CRON.D directory.
All files in this directory are used and/etc/the same syntax as in crontab. # Record the memory usage of the system every Monday # at3: 30AMinchThe file/tmp/Meminfo - 3* * Mon cat/proc/meminfo >>/tmp/Meminfo # Run custom script the first day of every month at4: 10AMTen 4 1* */root/scripts/backup.sh ExamplePanax Notoginseng-1. crontab example a user other than the root user can use the Crontab tool to configure cron tasks. All user-defined crontab are saved in the/varIn the/spool/cron directory,
and execute them using the identity of the user who created them. To create a crontab project as a user, log on as the user, and then type the CRONTAB-E command,
Edits the user's crontab using the editor specified by the VISUAL or editor environment variable. The file uses the same format as the/etc/crontab.
When a change to crontab is saved, the crontab file is saved according to the user name and written to the file/var/spool/cron/the username. The cron daemon is checked every minute/etc/crontab files, etc/cron.d/directories, and/var/spool/changes in the cron directory.
If a change is found, they will be loaded into memory. This way, you do not have to restart the daemon when a crontab file changes.
37.1.2. Controlling the use of cron/etc/cron.allow and/etc/The cron.deny file is used to restrict the use of cron. The two formats used by the control file are one user per line.
None of the two files allow spaces. If the control file is modified, the cron daemon (crond) does not have to be restarted. Using control files is read every time a user adds or deletes a cron task. The root user can always use cron regardless of what is specified in the control file. If the Cron.allow file exists, only the users listed in it are allowed to use cron, and the Cron.deny file is ignored. If the Cron.allow file does not exist, all users listed in Cron.deny are prohibited from using cron. 37.1.3start and stop services to start the Cron service, use the/sbin/service crond Start command. To stop the service, use the/sbin/Service crond Stop command. It is recommended that you start the service at boot time. Since Cron is a built-in service for Linux, you can start and shut down this service in the following ways:/sbin/service Crond Start//Start the service/sbin/service Crond Stop//Close Service/sbin/service Crond Restart//Restart Service/sbin/service Crond Reload//Reload Configuration..... Crontab in/the ETC directory exists under cron.d,cron.daily,cron.weekly,cron.monthly,cron.hourly five directories and crontab,cron.deny two files. Cron.daily is performed once a day job,cron.weekly is performed once a week job.cron.monthly is the job that executes once a month, Cron.hourly is a job.cron.d that is performed every hour of the day, but not by hours, days, weeks, months, and then under this directory. If it is done by the hour, by day, by week, by month, you can put it under the corresponding directory in front. Then some people may ask, in front of the day, by the week, the month of the job, exactly when to automatically execute it? By observing/etc/The crontab file is clear: [email protected]_std etc]$ Cat Crontabshell=/bin/Bashpath=/sbin:/bin:/usr/sbin:/usr/Binmailto=Roothome=/# Run-Parts on* * * * Root run-parts/etc/cron.hourly Geneva 4* * * Root run-parts/etc/cron.daily A 4* *0Root run-parts/etc/cron.weekly the 4 1* * Root run-parts/etc/cron.monthly/etc/a Cron.deny file is a feature that controls which users are not allowed to use crontab. In addition, in/var/There are two directory Cron,anacron below the spool. Where the cron directory below has each user's own through crontab-e Add the contents of the crontab. The Anacron directory below is the time that the last execution of Cron.daily,cron.monthly,cron.weekly was recorded. The cron service for Linux is to read every other minute/var/spool/cron,/etc/crontab,/etc/CRON.D all the content below. On Linux systems, by default, the/etc/The following files exist under the cron.daily directory:-rwxr-xr-x1Root root286The - 2004Tmpwatch-rwxr-xr-x1Root root276Sep in 20040anacron-rwxr-xr-x1Root root2133Dec1 2004PreLink-rwxr-xr-x1Root root theJul - 2005logrotate-rwxr-xr-x1Root root121The9 2005Slocate.cron-rwxr-xr-x1Root root -AprTen 2006Mcelog.cron-rwxr-xr-x1Root root418Apr - 2006 xx-Makewhatis.cron-rwxr-xr-x1Root root104May to 2006rpmlrwxrwxrwx1Root root -Apr7 ,: - xx-logwatch. /log.d/scripts/logwatch.pl Here are some things that are very resource-intensive and can be considered to be removed. The role of Tmpwatch is to erase some temporary files that have not been accessed for a long time. Here, keep it. The role of 0anacron is to update the execution time of the crontab job, which must be kept. It is in front of the name another 0, to ensure that the program will be executed before other programs. And this is run-parts is automatically called. PreLink's role is to pre-link some dynamic link libraries and executables to speed up startup time and reduce run-the memory allocation of time is somewhat similar to the role of Oracle's Dbms_shared_pool.keep. This thing is a double-edged sword. Logrotate's role is recycled, compressing some system logs, or keeping it. The role of Slocate.cron update slocate database, used for locate services, very resource-intensive, can be stopped. The role of Mcelog.cron is to generate/var/log/mcelog files, keep them. xx-The role of Makewhatis.cron is to create Whatis database, which is used for whatis services. More consumption of resources, can be removed. This also exists in the cron.weekly, which can also be removed. The role of RMP is to put information on the RPM packages installed on the system every day/var/log/rpmpkgs to go in. This is useless and can be removed. xxThe-logwatch function is used to monitor the Linux log file. You can keep them.

"Turn" crontab detailed

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.