To schedule a task in linux

Source: Internet
Author: User
This article mainly describes how to schedule tasks in linux. For more information, see

Schedule a one-time scheduled task: at: schedule the task to be executed once at a certain time point (usually use it)

Batch: Schedule a job to run once when the system load is not heavy

Step 1: # service atd start the at time of a one-time scheduled task

1. absolute timing method: midnightnoonteatimeHH: MM [today] HH: MM [tommorow] HH: mm week HH: MM mm MM/dd/yy 2. relative timing method

Copy codeThe code is as follows:
Now + n minutesnow + n hours
Now + n day

Specify to execute a command at this afternoon (assuming the current time is, 2009/9/16) at5: 30pmat17: 30at17: 30 todayatnow + 5 hoursatnow + 300minutesat17: 3016.9.2009at17: 309/16/2009

When the specified time is not reached, we can also write the command we want to execute to a file. for example, you can edit/bin/echo in the file by using vione.txt "##########"> a.txt#at-fone.txt

At-f File time point

To execute a program (command) at a certain time, you must use the absolute path of the command.

Copy codeThe code is as follows:
At10: 56 & gt;/bin/cp/root/*/home/> bin/echo "11111111" & gt;/root/one.txt

Ctrl + d exit at-l view or atqat-d or atrm delete a scheduled task

At execution result and configuration file

The at result is sent to the user who submits the command by email.

At configuration file: restrict which users can use at command/etc/. if allow exists in this file, users listed in this file can use the at command. If this file does not exist, query/etc/. deny

/Etc/at. deny if this file exists, users listed in the file cannot use the at command

If both files do not exist, only the root user can use the at command. If both files exist and are empty, all users can use the at command.

Crond # servicecrondstart for periodic scheduled tasks

The crond process searches for crond files and loads them into the memory.

The crontab file is the file named after the user name in the/var/spool/cron/directory.

After the crond process starts, he first checks whether the crontab file has been set by the user. if the crontab file is not transferred to the "sleep" status, the crond process wakes up every minute to release system resources,

Check the crontab file to determine whether a command needs to be executed. After the command is executed, any loss of output will be sent to the owner of crontab as an email.

# Crontab-e: periodic task editing

# Crontab-l view scheduled tasks

# Crontab-r delete the current scheduled task

Format of scheduled task writing:

Copy codeThe code is as follows:
Time-Sharing days, months, and weeks

[0--59] [0--23] [1--31] [1--12] [0--7] (0ro7issun)

*/, 71-5

Every two minutes, from Monday to Friday

None of these items can be blank and must be filled in

If you do not need to specify several items in the future, you can use the wildcard "*" to indicate

Multiple values can be specified for each time period. they can be separated by commas (,), 5-6 */3.

The command should provide the absolute path

You must have the permission to run crontab.

Copy codeThe code is as follows:
/Etc/cron. allow/etc/cron. deny

Similar to

Related Article

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.