Linux Crontab scheduled task commands
During work, the database needs to be automatically backed up at every day, so a scheduled task needs to be created. I chose to use Crontab in Linux to add a scheduled task to execute the shell file. The shell file has the Database Backup command.
1. Crontab Introduction
The crontab command schedules the execution of some commands at certain intervals.
2. view the/etc/crontab file
Vim/etc/crontab
3. The description format of each task in the file/etc/crontab is as follows:
Minute hour day month dayofweek command
Minute-integer from 0 to 59
Hour-integer from 0 to 23
Day-an integer from 1 to 31 (must be the valid date of the specified month)
Month-an integer from 1 to 12 (or a month abbreviated as Jan or Feb)
Dayofweek-an integer from 0 to 7. 0 or 7 is used to describe Sunday (or abbreviated as Sun or Mon)
Command-command to be executed (as ls/proc>/tmp/proc or command to execute custom scripts)
Root indicates running as root user
Run-parts indicates that a folder is followed by all the scripts in the folder.
For the preceding statements, asterisks (*) indicate all available values. For example, * indicates that the command is executed every month (other restrictions must be met.
The hyphen (-) between integers indicates an integer column. For example, 1-4 indicates an integer of 1, 2, 4.
The specified values are separated by commas. For example, 3, 4, 6, and 8 indicate the four specified integers.
The "/" symbol specifies the step setting. "/<Interger>" indicates the step value. For example, 0-59/2 is defined to be executed every two minutes. The step value can also be represented by an asterisk. For example, */3 is used to run a specified task every three months.
Comments starting with "#" are not executed.
If a cron task needs to be executed on a regular basis instead of by hour, day, week, or month, add the/etc/cron. d directory. All files in this directory have the same syntax as the/etc/crontab file. See the following example:
# Record the memory usage of the system every Monday
# At 3: 30 AM in the file/tmp/meminfo
30 3 ** mon cat/proc/meminfo>/tmp/meminfo
# Run custom scr pt the first day of every month at AM
10 4 1 **/root/scr restart pts/backup. sh
In addition to the root user, users can execute crontab configuration scheduler tasks. All user-defined crontabs are stored in the/var/spool/cron directory, and tasks are executed as creators. To create a crontab for a specific user, log on to the user and run the crontab-e command. The system starts editing crontab in the editing software specified in VISUAL or EDITOR. The file content is in the same format as/etc/crontab. Example:
0 3 ***/home/dbbackup/db1backup. sh backup
0 4 ***/home/dbbackup/db2backup. sh backup
Indicates that/home/dbbackup/db1backup. sh backup is executed at three o'clock every day, And/home/dbbackup/db2backup. sh backup is executed at four o'clock. If it is executed every five minutes, it can be changed:
*/5 */home/dbbackup/db2backup. sh backup
When the changed crontab needs to be saved, the file will be saved as the following file/var/spool/cron/username. The file name varies with the user name.
The cron Service Checks changes in the/etc/crontab,/etc/cron. d/,/var/spool/cron files every minute. If any change is found, it will be downloaded to the memory. Therefore, the program does not need to be restarted even if the crontab file changes. We recommend that you use the crontab-e command to add custom tasks. After exiting, use/etc/init. the d/crond restart command restarts the crond process. The official file says that you do not need to restart the process, but I cannot run the task without restarting it. At first, I don't know what the run-parts in the/etc/crontab file means. directly adding the command in the/etc/crontab format will always fail to run, later I learned that run-parts is followed by a folder.
4. Close the start of the crontab Service
Sbin/service crond start // start the service
/Sbin/service crond stop // close the service
/Sbin/service crond restart // restart the service
/Sbin/service crond reload // reload the configuration
Use crontab in Linux to create scheduled tasks
Routine scheduling of crontab in Linux
Linux crontab does not run troubleshooting
Ubuntu uses crontab for scheduled tasks
Linux scheduled task (at batch crontab anacron)
Linux task scheduler (at, crontab)
This article permanently updates the link address: