Linux Command details at scheduled task execution, linuxat

Source: Internet
Author: User

Linux Command details at scheduled task execution, linuxat
Command:

A task can be executed only once at a specified time.


Syntax: # at [parameter] [time]
At> executed command
Exit at command ctrl + d

Command prerequisites:
You need to enable the atd process (in redhat, atd is started with system startup by default)
In the test, centos6.5 mini version does not contain the at service. Therefore, you must download

# Yum-y install


# Check whether atd is enabled

# Ps-ef | grep atd


# Enable atd

#/Etc/init. d/atd start


# Set atd startup

# Chkconfig -- level 2345 atd on


Query and delete the current task to be executed
Query the current waiting task. The task is not displayed after it is executed.
# Atq


Delete the tasks created by at in the system that are waiting for execution
# Task ID of the atrm task
Example: # atrm 17


Common parameters:
-M: after a specified task is completed, an email is sent to the user even if no standard output is provided.
-I: the alias of atq
-D: alias of atrm
-V: displays the time when the task will be executed.
-C: print the task content to the standard output
-V: displays version information.
-Q: Add <queue> to use the specified queue
-F: Add <File> to the end to read the task from the specified file instead of the standard input.
-T: Later <time parameter> submit the task to run in the form of Time Parameter


Time: defines when the at task is to be executed. The format is as follows:
1. HH: MM
Note: The task is performed at HH: MM today. If the time has exceeded, the task is executed at HH: MM tomorrow.
Ex>

2, HH: MM YYYY-MM-DD
Note: This task is required to be performed at a special time of a day in a month of a year.
Ex>

3. HH: MM [am | pm] [Month] [Date]
Note: This task is required to be performed at a time point of a month or a day of a year.
Ex> 04 pm March 17

4. HH: MM [am | pm] + number [minutes | hours | days | weeks]
Note: This task is performed only after a certain time point is added.
Ex> now + 5 minutes
Ex> 04 pm + 3 days


Time Format extension:
At allows a quite complex set of time-based methods.
1. the time specified in the hh: mm (hour: minute) format of the current day can be accepted. If the time has passed, it will be executed on the next day.
2. You can use vague words such as midnight (late night), noon (noon), and teatime (tea time, usually four o'clock P.M.) to specify the time.
3. You can 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.
4. specify the date of command execution, in the format of month day (month day), mm/dd/yy (month/day/year) or dd. mm. yy (Day. month. the specified date must be later than the specified time.
5. Use the relative timing method. The specified format is: now + count time-units, now is the current time, and time-units is the time unit. Here it can be minutes (minutes), hours (hours), days (days) and weeks (week ). Count is the number of times, days, hours.
6. You can use today (today) and tomorrow (tomorrow) to specify the time to complete the command.


Restrict User Permissions
Premise: many hosts are most often found to have many hacking programs in their systems after being cracked by so-called attacks, these 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.
The control file used by the at command to restrict user control.
Control File directory:/etc/at. allow and/etc/at. deny
Rules for using control files:
1: Search for/etc/at first. the user who writes the allow file in this file can use at, and the user who does not have this file cannot use at (even if it is not written. in deny );
2: If/etc/. if allow does not exist, search for/etc/. if the file deny is written in. deny users cannot use at instead of. users in the deny file can use the at command.
3: If both files do not exist, only the root user can use the at command.
4: In general distributions, since all users on the system are trustworthy, the system usually keeps an empty/etc/. the deny file indicates that all users are allowed to use the at command.
5: if you do not want some users to use at, write the user's account to/etc/at. deny! One account writes one line.


Notes
1. If the at command output path is incorrect, the result will be sent to the user by email.
2. When a task is created, it is assigned a task number and will be queued in/var/spool/. We do not recommend that you use the vi editor to modify the settings, which is prone to errors.


Example:
Example 1: Run/bin/ls at five o'clock P.M. after three days
# At 5 + 3 days
At>/bin/ls
At> <EOT>
Job 7

Instance 2: tomorrow, and the output time is within the specified file
# At 17:20 tomorrow
At> date>/root/doiido. log
At> <EOT>
Job 8

Instance 3: After the task is scheduled, run the atq command to check whether the task is executed.
# Atq
8 a root
7 a root

Instance 4: delete a set task
# Atq
8 a root
7 a root
# Atrm 7
# Atq
8 a root

Instance 5: displays the configured task content.
# At-c 8
#! /Bin/sh
# Atrun uid = 0 gid = 0
# Mail root 0
Echo "hello"
Date> doiido. log


Extended command batch
Batch is a special version of the at command. It is used when a task is executed to occupy a large amount of resources. It is used only when the cpu requirement is lower than the cpu capability of 80%.
# Batch
At> echo "hi">/dev/tty2
The task created by batch is also viewed by atq and deleted by atrm.

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.