One linux Command every day-crontab and linux Command-crontab

Source: Internet
Author: User

One linux Command every day-crontab and linux Command-crontab

The crontab command is used to submit and manage users' tasks that require periodic execution. Similar to scheduled tasks in windows, this service tool is installed by default after the operating system is installed, the crond process will be started automatically. The crond Process regularly checks whether there are tasks to be executed every minute. If there are tasks to be executed, the crond process will be automatically executed.

Note:

The minimum interval of crontab is 1 minute.
Syntax:
Crontab (option) (parameter)
Option:
-E: edit the timer settings of the user;
-L: lists the timer settings of the user;
-R: Delete the timer settings of the user;
-U <User Name>: Specifies the user name to set the timer.
Parameters:
Crontab file: Specifies the crontab file containing the task to be executed.
Knowledge extension:
In Linux, task scheduling is divided into two types: System Task Scheduling and user task scheduling. System Task Scheduling: the tasks that the system periodically performs, such as writing cached data to the hard disk and clearing logs. There is a crontab file under the/etc directory, which is the configuration file for system task scheduling.
The/etc/crontab file contains the following lines:
SHELL =/bin/bash
PATH =/sbin:/bin:/usr/sbin:/usr/bin
MAILTO = "" HOME =/
# Run-parts
51 * root run-parts/etc/cron. hourly
24 7 * root run-parts/etc/cron. daily
22 4 ** 0 root run-parts/etc/cron. weekly
42 4 1 ** root run-parts/etc/cron. monthly

The first four rows are used to configure the environment variables for running crond tasks. The first line of SHELL variables specifies the shell to be used by the system. bash is used here, the PATH variable in the second line specifies the PATH for the system to execute the command. The MAILTO variable in the third line specifies that the crond task execution information will be sent to the root user by email. If the value of MAILTO variable is null, the task execution information is not sent to the user. The HOME variable in the fourth line specifies the main directory used for executing commands or scripts. User task scheduling: jobs that you regularly perform, such as user data backup and scheduled email reminders. You can use the crontab tool to customize your own scheduled tasks. All user-defined crontab files are saved in the/var/spool/cron directory. The file name is the same as the user name. The user permission file is as follows:
/Etc/cron. deny the crontab command is not allowed for users listed in this file.
/Etc/cron. allow users listed in this file can use the crontab command
/Var/spool/cron/the directory where all user crontab files are stored. Name the crontab file by user name. Meaning: In the crontab file created by the user, each row represents a task, each field in each row represents a setting. Its format is divided into six fields. The first five fields are time sets, and the sixth segment is the command segment to be executed. The format is as follows:
Minute hour day month week command order: minute hour day month week
Where:
Minute: minute. It can be any integer from 0 to 59.
Hour: indicates the hour, which can be any integer from 0 to 23.
Day: indicates the date, which can be any integer from 1 to 31.
Month: represents the month, which can be any integer from 1 to 12.
Week: the day of the week. It can be any integer from 0 to 7. Here 0 or 7 represents Sunday.
Command: the command to be executed. It can be a system command or a script file compiled by yourself.
You can also use the following special characters in the preceding fields:
Asterisk (*): represents all possible values. For example, if the month field is an asterisk, this command is executed every month after the conditions of other fields are met. Comma (,): values separated by commas (,) can be used to specify a list range, for example"
Middle bars (-): You can use the middle bars between Integers to represent an integer range. For example, "2-6" indicates "2, 3, 4, 5, 6" forward slashes (/): you can use a forward slash to specify the interval. For example, "0-23/2" indicates that the interval is executed every two hours. At the same time, the forward slash can be used with the star number, for example, */10. If it is used in the minute field, it indicates that the execution is performed every ten minutes. Crond 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
View the crontab service status:
Service crond status
Start the crontab service manually:
Service crond start
Run the following command to check whether the crontab service is set to start at startup:
Ntsysv
Add boot auto start:

Chkconfig-level 35 crond on

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.