Linux crontab scheduled task application

Source: Internet
Author: User

1. scheduled task application
1. at: Execute the specified command at the specified time. After the command is executed, the command is canceled from the system. Cron: periodically runs the specified command at the specified time.

Note: If the system is shut down at the time when the command is to be executed, the command will be executed at the same time when the system is started. For example, if the user wants to execute a command at and the at command is sent in the morning, on which day does the system execute the command? If the user is still working at, the command will be completed at this time. If the user shuts down before, the command will be executed at the next day (the condition is that the system must be started). What if the cron command is used ??

 

2.

1. command:

At // set the task

Atq // view the current task

Atrm // delete a set task

Syntax: # at [-Option] Time Format // sets the task

# Atq // view the current task

# Atrm [number] // delete a set task

Option: After m: at is completed, an email is sent to the user. The time format mainly includes the following: HH: MM is executed in today's HH: MM. If the time has exceeded, HH: MM will execute this job tomorrow. Example: # at12: 00 HH: MM YYYY-MM-DD in a certain day of a month to execute this job!

For example, # at12: 00 2006-12-30 HH: MM + number [minutes | hours | days | weeks] indicates that the task is executed after a specified time is added.


Example: # at + 1 days 2006-12-30

After entering at, enter the command input mode. Here you can repeat the command and press ctrl + D to exit. At12: 00 shutdown-h 0 // execute the shutdown command at 12 o'clock today.

# At12: 00 2006-12-30 tar czvf/dump/workdump.tar.gz/work/* // 2006-12-30 package and compress files in the/work directory

# At + 1 days 2006-12-30 rm-rf/work // 2006-12-31 delete/work directory

3. cron

1. cron: periodic execution task Syntax: crontab [-Option]

Option

-U: Specifies a user name for the option that only the root user can execute.

-L: List crontab content

-E: Edit crontab content

-R Delete

 

Crontab content servicecrondstart // start the service

# Servicecrondrestart // restart the service

# Servicecrondstop // stop the service

When you enter crontab-e, the VI screen is automatically displayed. The format of the edited text is five different time commands.

Five different time periods are shown in the following table:

59 23 1 5 * May 1 each year

30 16 ** 6: Execute the code at every Saturday *, which indicates that all time is applicable.

For example, system logs are backed up at on the first day of every month. 0 12 1 ** tar czvf/back/system. tgz/var/log/* crontab is a system task used by the user. You do not have to run the crontab command. You can directly edit/etc/crontab,

01 * root run-parts/etc/cron. hourly is followed by the root user after five times, which indicates that the execution identity is the root user. Run-parts indicates/etc/cron. hourly Is All executable files in a directory. (You can go to the/etc directory to check whether the system has preset several directories) you can also directly write the commands to be executed every day to/etc/cron. you only need to use crontab-e. Create a/root/runcron directory, and put the executable files that will be executed every five minutes under this directory, then, add */5 * root run-parts/root/runcron to the/etc/crontab file so that the system can execute all executable files in the directory every five minutes..

 

Note: in linux, crontab automatically reads/etc/crontab once every minute. since crontab is read to the memory, after you modify/etc/crontab, it may not be executed immediately. In this case, restart the cron service: # service crond restart

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.