Linux routine tasks (scheduled jobs)

Source: Internet
Author: User

Linux Timed Jobs (routine tasks)

There are two types of scheduled jobs for Linux:

? At: This job is performed only once and is canceled from the schedule in the Linux system;
? Cron: This job will continue on a routine basis!

At execution only once

To use at to perform a task at some point in the future, you must first open the service ATD, generally for the security system default ATD service is not turned on, use the command/etc/init.d/atd restart to open the service.

We can use the/etc/at.allow and the/etc/at.deny two files to carry out the usage limit of at. After adding these two files, at is actually working like this:
1. First find/etc/at.allow This file, written in this file users can use at, not in this file users can not use at (even if not written in At.deny);
2. If there is no/etc/at.allow to find/etc/at.deny this file, if it is written in this At.deny user can not use at, but not in this At.deny file users, it is possible to use at;
3. If none of the two files exist, then only root can use the AT command.

After the service is turned on, you can schedule the work with command at, and these one-time command tasks will be written to the folder/var/spool/at, then the work will go to the scheduled state to wait for execution, and the task will be removed from the file when the task execution is completed. Use the command at to write the task to the folder/var/spool/at, at the specific usage:

Well, let's talk about the grammar at this thing!
[[email protected] ~]# at [-m] Time
Parameters:
-M: When the work of at is completed, the user is notified by email that the work has been completed.
Time: Date format, where you can define the "when to do at this work" time, the format is:
hh:mm ex> 04:00

hh:mm yyyy-mm-dd ex> 04:00 2005-12-03
It is mandatory to make this work at a particular time of day of the month of the year!
HH:MM[AM|PM] [Month] [Date] ex> 04pm December 3
also, force a certain time in a certain day of the year!
HH:MM[AM|PM] + number [Minutes|hours|days|weeks]
ex> now + 5 minutes ex> 04pm + 3 days
that is, "add a few more hours" at some point in time.
Example:
Example one: After five minutes, send the/ROOT/.BASHRC to the Dmtsai user
[[email protected] ~]# at now + 5 minutes
at>/bin/mail dmtsai-s "Testing at Job" </ROOT/.BASHRC
at> <EOT> <== here [Ctrl] + D will appear <EOF> words! The end of the rep!
Job 8 at 2005-09-07 10:47
# above this line of information in the description, the 8th at work will be conducted in 2005/09/07 10:47!
example two: Because the computer room is expected to power down in 2005/09/16, I want to shut down in 2005/09/15 23:00?
[email protected] ~]# at 23:00 2005-09-15
at>/bin/sync
at>/bin/sync
at>/sbin/shutdown-h now
at> <EOT>
job Ten at 2005-09-15 23:00

This is an AT command I executed after 5min, you can see the changes in the file under the/var/spool/at folder

To view a timed job for at and cancel a scheduled job that already exists

ATQ displays all scheduled tasks that have been set, ATRM num Deletes a timed job with an ordinal

Crontab cycle execution of timed jobs

Use the instruction crontab command to add a timed job that is executed in a loop, and at similar use this service requires permission first,

? /etc/cron.allow: will be able to use the Crontab account can be written to it, if not in this file users are not allowed to use crontab;
/etc/cron.deny: You will not be able to use the Crontab account to write to it, if not recorded in this file users, you can use the crontab.

First checks whether the user exists in/etc/cron.allow, the presence is allowed, if the user is not found in/etc/cron.allow, the file is looked up/etc/cron.deny if no user exists then the user can add a timed job. When a timed job is added, it is written to the file/var/spool/cron/.

Crontab usage

[ email protected] ~]# crontab [u username] [-l|-e|-r]
Parameters:
-u: Only root can do this task, that is, to help other users to establish/remove crontab;
-E: Edit Crontab's work
-L: Check the crontab's work content
-R: Removal of Crontab's work content
Example:
Example one: write to yourself at 12:00 per day with Dmtsai
[email protected] ~]$ crontab-e
# At this time will go into the VI editing screen let you edit work! Notice that each job is a row.
0 * * * mail Dmtsai-s "at" </HOME/DMTSAI/.BASHRC
|<============== Instruction string ========================>| for the sun and Moon Week #分

Use CRONTAB-E to add timed jobs, crontab-l show timed jobs.

The five * numbers represent the meaning from left to right, and when the week is 0 or 7 o'clock, it means "Sunday"!

Linux routine tasks (scheduled jobs)

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.