Linux crontab Timing Task Commands

Source: Internet
Author: User

Linux Crontab Timing Task Commands[Date: 2016-02-13] Source: Linux Community

The database needs to be automatically backed up at 0 points per day, so a scheduled task needs to be established. I chose to use crontab to add a timed task to execute the shell file under Linux. The shell file has a database backup command.

I. Crontab INTRODUCTION

The function of the crontab command is to schedule execution of some commands at certain intervals.

Two View/etc/crontab File

Vim/etc/crontab

Three Each line of the task in the file/etc/crontab is described in the following format:

Minute hour day Month DayOfWeek command

minute-integers from 0 to 59
hour-integers from 0 to 23
Day-an integer from 1 to 31 (must be a valid date for the specified month)
Month-an integer from 1 to 12 (or a month such as the Jan or Feb abbreviation)
DayOfWeek-integers from 0 to 7, 0 or 7 to describe Sunday (or as represented by sun or mon shorthand)
Command-commands to execute (commands that can be used as Ls/proc >>/tmp/proc or execute custom scripts)

Root indicates to run as root user
Run-parts means a folder followed by all the scripts under that folder

For each of these statements, the asterisk (*) represents all available values. For example, when referring to month, the command is executed monthly (subject to other restrictions).
The hyphen (-) between integers denotes an integer column, for example 1-4 means an integer 1,2,3,4

The specified value is separated by commas. Such as: 3,4,6,8 represents these four specified integers.

The symbol "/" specifies the stepping setting. "/" indicates a stepping value. such as the 0-59/2 definition is executed every two minutes. The step value can also be represented by an asterisk. such as */3 is used to run a specified task every three months running.

A comment line that begins with "#" is not executed.

If a cron task needs to be performed on a regular basis instead of by the hour, day, week, and month, you need to add the/ETC/CRON.D directory. All files and files in this directory are/etc/crontab in the same syntax, see the sample:

# Record the memory usage of the system every Monday
# at 3:30AM in the File/tmp/meminfo
3 * Mon cat/proc/meminfo >>/tmp/meminfo
# Run Custom Scrīpt the first day of every month at 4:10AM
4 1 * */root/scrīpts/backup.sh

Users other than the root user can perform crontab configuration scheduled tasks. All user-defined crontab are stored under directory/var/spool/cron, and the task is executed as the creator. To create a crontab with a specific user, first log in as that user, execute command crontab-e, and the system initiates the editing crontab that is specified in visual or editor. The file content is the same as the/etc/crontab format. Examples are as follows:

0 3 * * */home/dbbackup/db1backup.sh Backup
0 4 * * */home/dbbackup/db2backup.sh Backup

Represents 3 points per day to perform/home/dbbackup/db1backup.sh backup,4 point execution/home/dbbackup/db2backup.sh Backup, if it is executed every five minutes can be changed to:

*/5 * * * */home/dbbackup/db2backup.sh Backup

When the changed crontab needs to be saved, the file is saved in the file/var/spool/cron/username as follows. The file name differs depending on the user name.

The Cron service checks for changes in/etc/crontab,/etc/cron.d/,/var/spool/cron files every minute. If a change is found, it is downloaded to the memory. Therefore, even if the crontab file changes, the program does not need to be restarted. The recommended custom task is added using the CRONTAB-E command, which restarts the crond process with the/etc/init.d/crond Restart command, and the official file says that it does not restart the process, but I am not able to run the task without restarting. Start do not know/etc/crontab file run-parts what meaning, direct command in accordance with the/etc/crontab format plus always can not run, later only know run-parts refers to the folder followed by.

Four Startup shutdown for Crontab services

Sbin/service Crond Start//Startup service
/sbin/service Crond stop//Shut down service
/sbin/service crond Restart//Restart service
/sbin/service Crond Reload//Reload Configuration

Use Crontab to create scheduled tasks in Linux http://www.linuxidc.com//Linux/2013-06/86401.htm

Crontab routine work arrangement in Linux http://www.linuxidc.com//Linux/2013-06/85441.htm

Linux Crontab does not perform troubleshooting http://www.linuxidc.com//Linux/2013-06/85432.htm

Ubuntu uses crontab timed task http://www.linuxidc.com//Linux/2013-05/84770.htm

Linux Scheduled Tasks (at Batch crontab Anacron) http://www.linuxidc.com//Linux/2013-03/81584.htm

Linux Task Scheduler (At,crontab) http://www.linuxidc.com/Linux/2015-09/122970.htm

This article permanently updates the link address : http://www.linuxidc.com/Linux/2016-02/128323.htm

Linux crontab Timing Task Commands

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.