In Windows systems, Windows provides the ability to schedule tasks, such as task scheduling in Control Panel, performance and maintenance, and its function is to schedule tasks to run automatically. You can set up a scheduled task by stepping through the "Add a task plan" step-by-step guide.
In a Linux system you may have found out why the system often does some tasks automatically. Who are those who are at the mercy of their work? In a Linux system, what if you want your own backup program to start running under the system automatically at some point in time, without having to start it manually? These routine work may be divided into one-time timing work and cycle time work, in the system is also what services in charge? Also, if you want to send a letter every year on your wife's birthday, remind yourself not to forget what the Linux system should do?
Today we mainly learn about the use of a one-time scheduled task at command!
1. Command format:
at[parameters [TIME]
2. Command function:
Executes a specified task at a specified time, only once, and requires the ATD process to be turned on (
Ps-ef | grep ATD View, open with/etc/init.d/atd start or restart, boot up is required to run Chkconfig--level 2345 ATD on).
3. Command parameters:
-M sends a message to the user when the specified task is completed, even if there is no standard output
#p # page Title #e#-i ATQ Alias
-D ATRM Aliases
-V shows when the task will be executed
-C Print Task content to standard output
-V Display version information
-q< Queue > Use specified queue
-f< file > read from a specified file into a task instead of reading from a standard input
-t< Time parameter > Submit a task to run in the form of a time parameter
At allows you to use a fairly complex set of time-specific methods. He was able to accept the time specified in the hh:mm (hour: minute) of the day. If the time has passed, then it will be executed the next day. Of course, you can use Midnight (late night), noon (noon), Teatime (tea time, usually 4 o'clock in the afternoon) and other vague words to specify the time. The user is also able to use the 12-hour timekeeping system, which is either a AM (morning) or PM (afternoon) After the time to indicate whether it is morning or afternoon. You can also specify a specific date for the execution of the command, specifying the format for Month Day (month) or mm/dd/yy (Month/day/year) or Dd.mm.yy (day, month, year). The specified date must be followed by the specified time. The absolute timing method is described above, and the relative timing method can be used, which is good for arranging orders that will be executed soon. The specified format is: Now + Count Time-units, today is the current time, Time-units is the time unit, here can be minutes (minutes), hours (hours), Days (day), Weeks (week). Count is the amount of time, whether it is a few days, or a few hours, and so on. A more timed method is to specify the time to complete the command directly using today, tomorrow (tomorrow).
Time: Date format, where you can define when to do at this task, in the following format:
hh:mm
ex> 04:00#p# pagination Title #e#
At today's hh:mm time, if that moment is over, tomorrow's hh:mm will do the job.
hh:mm YYYY-MM-DD
Ex> 04:00 2009-03-17
To mandate the task at a particular time of day of the month of the year.
HH:MM[AM|PM] [Month] [Date]
Ex> 04pm March 17
Also, forcing a certain day of the year to perform the task at some point in the month
HH:MM[AM|PM] + number [Minutes|hours|days|weeks]
Ex> now + 5 minutes
Ex> 04pm + 3 days
That is, it takes a few more minutes to do that task at a certain point in time.
4. Usage examples:
Example 1: Three days after 5 o'clock in the afternoon Chung execution of/bin/ls
#p # Paging Header #e# command:
At 5pm+3 days
Output:
[Email protected] ~]# at 5pm+3 days
At>/bin/ls
At> <EOT>
Job 7 at 2013-01-08 17:00
[Email protected] ~]#
Description
Example 2: Tomorrow 17 o'clock, the output time is within the specified file
Command:
At 17:20 tomorrow
Output: #p # page Title #e#
[Email protected] ~]# at 17:20 tomorrow
At> Date >/root/2013.log
At> <EOT>
Job 8 at 2013-01-06 17:20
[Email protected] ~]#
Description
Example 3: After scheduling a task, we can use the ATQ command to see that the system is not performing a work task until it is executed.
Command:
Atq
Output:
#p # Pagination title #e#[[email protected] ~]# ATQ
8 2013-01-06 17:20 a root
7 2013-01-08 17:00 a root
[Email protected] ~]#
Description
Example 4: Delete a task that has already been set
Command:
ATRM 7
Output:
[Email protected] ~]# ATQ
8 2013-01-06 17:20 a root
#p # pagination Title #e#7 2013-01-08 17:00 a root
[Email protected] ~]# ATRM 7
[Email protected] ~]# ATQ
8 2013-01-06 17:20 a root
[Email protected] ~]#
Description
Example 5: Displaying the contents of a task that has been set
Command:
At-c 8
Output:
[Email protected] ~]# At-c 8
#p # pagination Title #e##!/bin/sh
# Atrun Uid=0 gid=0
# Mail Root 0
Umask 22 omit n characters here
Date >/root/2013.log
[Email protected] ~]#
Description
Example 6:
Command:
Output:
Description
5. How the ATD starts and at runs:
#p # Page Header #e#5.1 ATD start
To use a one-time scheduling task, our Linux system must have a service that is responsible for this program, which is the ATD service. However, not all Linux distributions will be opened by default, so at some point we need to manually activate the ATD service. The activation method is simple:
Command:
/ETC/INIT.D/ATD start
/ETC/INIT.D/ATD restart
Output:
[[email protected]/]#/etc/init.d/atd start
[Email protected]/]#/ETC/INIT.D/ATD
Usage:/etc/init.d/atd {start|stop|restart|condrestart|status}
[[email protected]/] #p # page title #e##/etc/init.d/atd stop
Stop atd:[OK]
[Email protected]/]# Ps-ef|grep ATD
Root 25062 24951 0 14:53 pts/0 00:00:00 grep ATD
[[email protected]/]#/etc/init.d/atd start
[OK]td:[OK]
[Email protected]/]# Ps-ef|grep ATD
Root 25068 1 0 14:53? 00:00:00/usr/sbin/atd
Root 25071 24951 0 14:53 pts/0 00:00:00 grep ATD
[root#p# pagination title #e# @localhost/]#/etc/init.d/atd Restart
Stop atd:[OK]
[OK]td:[OK]
[Email protected]/]#
Description
/ETC/INIT.D/ATD start does not start, the ATD service is started directly
/ETC/INIT.D/ATD Restart Service has been started, restart the ATD service
Note: Configure startup to start this service, so that every restart must be done again
Command:
Chkconfig ATD on
Output:
[[email protected]/]# chkconfig ATD on#p# Page Title #e#
[Email protected]/]#
How the 5.2 at operates
Since it is a scheduled task, there should be a way for the task to execute, and these tasks will be queued to the schedule. So how does a planned task occur? In fact, we use the AT command to generate the scheduled task to be run, and to write the scheduled task into the/var/spool/at/directory as a text file, which can wait for the ATD service to be taken and run. It's so simple.
However, not all people are allowed to do at the scheduled task. Why? Because of the system security reasons. Many hosts by the so-called attack, most often found that their system is a lot of hacking programs, these programs are likely to use a number of scheduled tasks to run or collect your #p# page Title #e# system operation information, and regularly sent to the hacker. So, unless you have an approved account, don't let them use the AT command first. How can you control the use of at?
We can use the two files of/etc/at.allow and/etc/at.deny to limit the usage of the at. After adding these two files, at is working like this:
First find/etc/at.allow This file, written in this file users can use at, no user in this file can not use at (even if not written in At.deny);
If the/etc/at.allow does not exist, look for/etc/at.deny this file, if the user written in this at.deny can not use at, but not in this At.deny file users, it is possible to use the AT command.
If none of the two files exist, then only root can use the AT command.
With this explanation, we know that/etc/at.allow is a more rigorous way of managing, while/etc/at.deny is more loosely (because the account is not in the file, it is able to run at). In general distributions, because it is assumed that all users on the system are trustworthy, an empty/etc/at.deny file is usually retained, meaning that all people are allowed to use the AT command (you can check the file yourself). However, in case you don't want some users to use at, write the user's account to/etc/at.deny! One account to write a line.
Reproduced in: http://www.itxuexiwang.com/a/liunxjishu/2016/0306/245.html?1457358449
One Linux command per day: at command