Scheduled Tasks in Linux

Source: Internet
Author: User
Tags stdin

Task or job: scheduled command

At : Schedule A one-time task

A System daemon (ATD), which has a set of command-line tools to interact with the daemon; The ATD Daemon provides a-to-Z total of 26 queues, the jobs are arranged alphabetically, and the lower the system priority

At <timespec>: When a new job is scheduled, at will then read the commands executed from stdin. For larger commands and typos-sensitive commands, using input redirection from a script file is easier than manually entering a command in a terminal window, and ctrl+d can complete input when manually entered

eg :

Now +5min relative time, from now on, 5 minutes after execution

Teatime tomorrow noon Midnight Blur Time

Noon +4days from noon onwards, 4 days later

5pm August 3 year August 3 5 o'clock in the afternoon

Check Job

ATQ | at–l: View the jobs to be processed by the user

displayed as four columns: job number, date and time of the job schedule, queue where the job is located, job owner

Ordinary non-privileged users can only view and control their own jobs, root to view and manage all jobs

at–c <jobnumber>: Check the actual command that will run when the job is executed

ATRM <jobnumber>: The scheduled job will be deleted

Cron Schedule Recurring Jobs

Crond daemon Default boot-up, controlled by multiple profiles and system-wide files, gives users and administrators granular control over the exact time when periodic jobs should be performed

Crond The daemon sends the result of the task to the owner of the task in the form of a message;

But you can also redirect task execution results to/dev/null without sending it to the mailbox and consuming resources

crontab–l list The current user's scheduled Tasks

Crontab-r Delete all scheduled tasks for the current user

crontab-e edit a scheduled task for the current user

crontab <filename> Delete all jobs and replace them with jobs read from <filename>, if no files are specified, the stdin

Root can use-u<username> to manage other users ' jobs

Job format

The edited file has one job per line, a blank line is allowed, and the line of the comment begins with the hash sign #, and the environment variable can also be declared with the format Name=value

Each job contains six fields that describe the time and content of the execution:

User-level tasks

Time-sharing Weekly command

System-Level tasks:

Time-sharing Week username command

The first five fields all use the same syntax rules

* insignificant, always, any valid value

number of minutes, hours, date, weekday, etc.

-    indicates the range, continuous time such as x, Y (inclusive)

, representing the list, discrete time

*/x x represents the time interval, how often it is executed

You can also use the three-letter alphabet to indicate the month and weekday

The last field contains the command to execute. If the shell environment variable is not declared, the command is executed by/bin/sh

If the command contains an escaped percent percent, the percent is treated as a new line, and all content after% is fed back to the command in stdin

eg

0 9 2 2 */usr/local/bin/yearly_backup

Execute/usr/local/bin/yearly_backup on February 2 9 o'clock in the morning every year

*/7 9-16 * Jul 5 echo "Chime"

Output chime to the job owner every 7 minutes from 9 o'clock in the morning to 4 o'clock in the afternoon every Friday in July

* * 1-5/usr/local/bin/daily_report

from Monday to Friday 23:58 the execution of/usr/local/bin/daily_report

3 * * * * echo Hiya

Output Hiya at the 3rd minute of every hour (1:3, 2:3, 3:3)

* * * * * 1,5 ls/tmp

Monday, Friday ls/tmp per minute

10,40 * * * * ls/tmp

10 points per hour, 40 tick execution, i.e. every 30 minutes execution of Ls/tmp

Scheduling System Cron Jobs

The system cron job defines the user between the day of the week and the command field to specify which users the job should run under

System cron jobs are defined in 2 locations:/etc/crontab and/etc/cron.d/*, packages that install cron jobs should have files placed in/etc/cron.d/to perform installation operations, but administrators can also use this location to separate related jobs into a single file

Pre-defined jobs are not available for hours, daily, weekly, and monthly, and these jobs are executed separately in/etc/cron.hourly/,/etc/cron.daily/,/etc/cron.weekly/, and/etc/ All the scripts in the cron.monthly/.

Make sure that all scripts located in these directories are executable and will not run if the script is not executed only.

/etc/cron.hourly/* The script is executed from the job defined in/etc/cron.d/0hourly using the Run-parts command. Daily, weekly, and monthly assignments are also performed using the Run-parts command.


Scheduled Tasks in Linux

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.