How to Use the scheduled task at command in Linux

Source: Internet
Author: User

Usage of AT commands for scheduled tasks (one-time scheduled tasks) in Linux

1. Command Format:

At [parameter] [time]

2. command functions:

You can run a specified task only once at a specified time. You must enable the ATD process (PS-Ef | grep ATD view, and enable/etc/init. d/ATD start or restart; run chkconfig -- level 2345 ATD on when starting the system ).

3. command parameters:

-M after the specified task is completed, an email is sent to the user even if no standard output is provided.

-I ATQ alias

-D atrm alias

-V: display the time when the task will be executed

-C: print the task content to the standard output

-V: display version information

-Q <queue> use the specified queue

-F <File> reads a task from a specified file instead of a standard input

-T <time parameter> submit the task to run as a Time Parameter

 

At allows a quite complex set of time-based methods. Acceptable inHh: mm (hour: minute)Time specified. If the time has passed, it will be executed on the next day. Of course, you can also use vague words such as midnight (late night), noon (noon), teatime (tea time, usually four o'clock P.M.) to specify the time. The user can also use a 12-hour hourly system, that is, add am (morning) or PM (afternoon) after the time to indicate whether it is morning or afternoon. You can also specify the specific date of command execution, in the format of Month day (Month day), mm/DD/yy (month/day/year) or DD. mm. YY (Day. month. year ). The specified date must be later than the specified time. The above is the absolute timing method. In fact, the relative timing method can be used, which is very good for the command to be executed soon. The specified format is: Now + count time-units,Now is the current time, Time-units is the unit of time, which can beMinutes (minutes), hours (hours), days, and weeks (weeks ).Count indicates the number of times, days, hours, and so on. Another method of timing is to use it directly.Today (today), Tomorrow (tomorrow)To specify the time when the command is completed.

Time: time format. You can define the time when the at task is to be executed. The formats include:

Hh: mm

Ex>

This task is performed at hh: Mm today. If the time has exceeded, HH: Mm tomorrow will perform this task.

Hh: Mm YYYY-MM-DD

Ex>

Forces the task to be performed at a special time of a certain day of a certain year or month.

Hh: Mm [am | PM] [month] [date]

Ex> 04 PM March 17

The same is true. This task is forced to be executed at a certain time point in a certain year, month, or day.

Hh: Mm [am | PM] + number [minutes | hours | days | weeks]

Ex> now + 5 minutes

Ex> 04 PM + 3 days

That is to say, the task will be executed only a few more times at a certain time point.

 

4. Example:

Instance 1:Five o'clock P.M. three days laterRun/bin/ls

Command:

At 5 PM + 3 days

Output:

[Root @ localhost ~] # At 5 + 3 days

At>/bin/ls

At> <EOT> press Ctrl + d

Job 7

[Root @ localhost ~] #

 

Instance 2:17 o'clock tomorrow, The output time is within the specified file

Command:

At 17:20 tomorrow

Output:

[Root @ localhost ~] # At 17:20 tomorrow

At> date>/root/2013.log

At> <EOT> press Ctrl + d

Job 8

[Root @ localhost ~] #

Instance 3: after the scheduled task is set, we canRun the ATQ command to check whether the system does not execute tasks.

Command:

ATQ

Output:

[Root @ localhost ~] # ATQ

8 A root

7 A root

[Root @ localhost ~] #

Instance 4:Delete A set task

Command:

Atrm 7

Output:

[Root @ localhost ~] # ATQ

8 A root

7 A root

[Root @ localhost ~] # Atrm 7

[Root @ localhost ~] # ATQ

8 A root

[Root @ localhost ~] #

 

Instance 5:Display the content of the configured task

Command:

At-C 8

Output:

[Root @ localhost ~] # At-C 8

#! /Bin/sh

# Atrun uid = 0 gid = 0

# Mail root 0

Umask 22 N characters are omitted here

Date>/root/2013.log

[Root @ localhost ~] #

 

5. How to start and run ATD:

5.1 ATD startup

To use a one-time scheduled task, the atd service must be provided on the Linux system. However, not all Linux distributions will open it by default. Therefore, you must manually activate the atd service at some time points. The activation method is simple:

Command:

/Etc/init. d/ATD start

/Etc/init. d/ATD restart

Output:

[Root @ localhost/] #/etc/init. d/ATD start

[Root @ localhost/] #/etc/init. d/ATD

Usage:/etc/init. d/ATD {START | stop | restart | condrestart | status}

[Root @ localhost/] #/etc/init. d/ATD stop

Stop ATD: [OK]

[Root @ localhost/] # ps-Ef | grep ATD

Root 25062 24951 0 00:00:00 pts/0 grep ATD

[Root @ localhost/] #/etc/init. d/ATD start

[OK] TD: [OK]

[Root @ localhost/] # ps-Ef | grep ATD

Root 25068 1 0 14: 53? 00:00:00/usr/sbin/ATD

Root 25071 24951 0 00:00:00 pts/0 grep ATD

[Root @ localhost/] #/etc/init. d/ATD restart

Stop ATD: [OK]

[OK] TD: [OK]

[Root @ localhost/] #

Note:

When/etc/init. d/ATD start is not started, start the atd service directly.

Restart the atd service after the/etc/init. d/ATD Restart service is started.

 

Note: Configure to start the service at startup, so that you do not have to start the service again at every restart.

Command:

Chkconfig ATD on

Output:

[Root @ localhost/] # chkconfig ATD on

[Root @ localhost/] #

 

5.2 At running mode

Since the task is scheduled, there should be a way to execute the task, and these tasks are arranged in the table. So how does one plan tasks? In fact, we use the AT command to generate the scheduler task to be run and write the scheduler task to the/var/spool/AT/directory in the form of text files, this work will be able to wait for the access and operation of the atd service. That's simple.

However, not all people can schedule at tasks. Why? Because of system security. After many hosts are attacked and cracked, many hackers are found in their systems.ProgramThese programs are very likely to use some scheduled tasks to run or collect your system running information, and regularly send it to hackers. Therefore, do not use the AT command unless it is an account that you acknowledge. So how can we achieve the controllable use of?

We can use the/etc/at. allow and/etc/at. deny files to restrict at usage. After these two files are added, the at operation is like this:

Search for the/etc/at. allow file first. Only users in the file can use at. Users in this file cannot use at (even if they are not written in at. deny );

If/etc/. if allow does not exist, search for/etc/. if the file deny is written in. deny users cannot use at instead of. the user in the deny file can use the AT command.

If neither file exists, only root can use the AT command.

Through this instruction, we know/etc/. allow is a strict management method, while/etc/. deny is loose (because the account is not in the file, it can run ). In general distributions, since all users on the system are trustworthy, the system usually keeps an empty/etc/. deny file, which means allowing everyone to use the AT command (you can check the file by yourself ). However, if you do not want some users to use at, write the user's account to/etc/at. deny! One account writes one line.

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.