One Linux command per day--crontab

Source: Internet
Author: User

The crontab command is used to submit and manage the tasks that the user needs to perform periodically, 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, and the Crond process periodically checks for the tasks to be performed every minute. If there is a task to perform, the task is automatically performed.

Attention:

The minimum interval for crontab is 1 minutes.
Syntax:
Crontab (option) (parameter)
Options:
-E: Edit the user's timer settings;
-L: Lists the user's timer settings;
-R: Delete the user's timer settings;
-u< user name;: Specifies the name of the user to set the timer.
Parameters:
Crontab file: Specifies the crontab file that contains the task to be performed.
Knowledge Expansion:
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.
The/etc/crontab file includes the following lines:
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto= "" home=/
# Run-parts
* * * * * Root run-parts/etc/cron.hourly
7 * * * Root run-parts/etc/cron.daily
4 * * 0 root run-parts/etc/cron.weekly
4 1 * * Root run-parts/etc/cron.monthly The first four lines are the environment variables that are used to configure the Crond task to run, the first line of the shell variable specifies which shell the system will use, this is bash, The second line of the path variable specifies the path of the system execution command, and the third line of the mailto variable specifies that Crond's task execution information will be emailed to the root user, and if the value of the mailto variable is null, the task execution information is not sent to the user. The four-row home variable specifies the home directory to use when executing the command or script. User Task scheduling: Users to perform regular work, such as user data backup, scheduled email reminders and so on. Users can use the Crontab tool to customize their own scheduled tasks. All user-defined crontab files are saved in the/var/spool/cron directory. Its file name is the same as the user name, and the consumer permissions file is as follows:
/etc/cron.deny the user listed in this file does not allow the crontab command to be used
/etc/cron.allow the users listed in this file are allowed to use the crontab command
/var/spool/cron/the directory where all users crontab files are stored, named after the user name crontab the meaning of the file: Each line in the crontab file created by the user represents a task, each field of each row represents a setting, and its format is divided into six fields. The first five paragraphs are time-setting segments, and the sixth is the command segment to execute, in the following format:
Minute hour day Month Week command order: time-sharing week
among them:
Minute: Represents minutes, which can be any integer from 0 to 59.
Hour: Represents the hour, which can be any integer from 0 to 23.
Day: Represents a date, which can be any integer from 1 to 31.
Month: Represents the month, which can be any integer from 1 to 12.
Week: Represents the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday.
Command: The commands to execute can be either system commands or script files that you write yourself.
in each of these fields, you can also use the following special characters:
Asterisk (*): represents all possible values, such as the month field if it is an asterisk, the command action is executed monthly after the constraints of other fields are met. Comma (,): You can specify a list range with a comma-separated value, for example, "1,2,5,7,8,9"
Mid-Bar (-): You can use the middle bar between integers to represent an integer range, such as "2-6" for "2,3,4,5,6" forward slash (/): You can specify the interval frequency of the time with a forward slash, for example "0-23/2" means to execute every two hours. A forward slash can be used with asterisks, such as */10, if used in the minute field, which means that it executes every 10 minutes. Crond Service
/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
View crontab Service Status:
Service Crond Status
To start the crontab service manually:
Service Crond Start
To see if the crontab service is set to boot, execute the command:
Ntsysv
Add to boot auto start:

Chkconfig–level Crond on

One Linux command per day--crontab

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.