Previous section review:
- Use of AT command
- Job: Create a task 10 minutes after shutting down the machine
At now+10 minutes
At>shutdown
At><eot>
In this section we proceed to the second command of the routine task management command: Cron
Before using the command, see if the Crond service is turned on
Service Crond Status
If it is not turned on, it can be opened with service Crond start
Note: Some Linux system service Cron status to view.
1. Editing Task Crontab–e
The format of the crontab command is as follows
* * * * * command
This format is preceded by 5 * followed by a command to execute
The meanings of 5 stars are:
The first *, representing minutes, 1-59, per minute can be expressed in * and */1
The second *, representing the hour, 0-23
The third *, which represents a date, 1-31
Fourth *, indicating the month, 1-12
Fifth *, representing the week, 0-6,0 said Sunday
Here are some examples to illustrate
* * * * * echo ' hello ' >>/tmp/test.txt
*/1 * * * * echo ' hello ' >>/tmp/test.txt
The above indicates that the output of Hello is executed every minute and the output is written to the/tmp/test.txt file
After you save the exit, you can see that the hello is output in the/tmp/test.txt
More examples:
* */1 * * * echo ' hello ' >>/tmp/test.txt
Indicates hourly execution
* 23-3/1 * * * echo ' hello ' >>/tmp/test.txt
Indicates that 23 to 3 points are executed every hour.
* * * echo ' hello ' >>/tmp/test.txt
To be executed 8:30 every night.
1 * * echo ' hello ' >>/tmp/test.txt
Indicates 1th # 10:10 per month to perform operations
1 1 * echo ' hello ' >>/tmp/test.txt
Represents an operation on January 1 10:10 every year
Ten * * 1 echo ' Hello ' >>/tmp/test.txt
Represents every Monday 10:10 operation
2. View Task Crontab–l
Use Crontab–l to see all your custom tasks
The command exists in the/var/spool/cron/root file
3. Delete All Tasks Crontab–r
Use Crontab–r to delete all custom tasks
4. System built-in timer task
Below the/etc/you can see
There are cron.daily,cron.hourly,cron.monthly,cron.weekly folders that represent the daily, hourly, monthly, and weekly scheduled tasks to be performed by the system. Take one of these as an example to see the system's timing tasks
Job: Define a timed task that outputs Hello world to the/tmp/test.txt file every minute
Follow the public number "get kicked genius" and watch the free video tutorial
Linux System Command Learning Series-timed Task crontab command