Linux OPS-Scheduled Tasks (September 5)

Source: Internet
Author: User

1. Summarize the detailed usage method of the task plan (at, crontab) on Linux system;
Task Scheduler: Perform a task at a point: at,batch
Periodic execution: crontab
The AT command execution results are sent to the mailbox of the scheduled task user by mail:/var/spool/mail/username
At [options] ... Time
Ctrl+d for submission
Time: You can have the following formats:
(1) Absolute time
Mmdd[cc]yy, Mm/dd/[cc]yy,[cc]yy or [cc]yy-mm-dd
(2) Relative time
now+ #UNIT
Minute, hour, day, week
(3) Blur time
Common options:
-Q queue:at Job queue;
-f/path/from/somefile: Reads the job to be run from the specified file;
-L: View a list of such running jobs in the job queue; equivalent to using the ATQ command;
-C At_job_num: Look at the contents of the running job;
-D: Delete the specified job; equivalent to ATRM
At configuration files:/etc/at.deny and/etc/at.allow
If deny exists alone, then all users except deny can use the AT command
If Allow is present alone, only allowed users can use the AT command
If it exists at the same time, only allow users to use the AT command
Batch: You do not need to specify a time to automatically perform the specified task when the system is idle. Other usages are similar to at
Crontab: Recurring scheduled task, daemon for Crond
(1) System cron Task: No default run identity, need to specify run, configuration file is/etc/crontab
* * * * * * user-name command to be executed
Run commands running as a user for minutes, hours, and weeks, respectively
(2) User cron task, submitted by a user, run as the user's identity
Configuration file is/var/spool/cron/username
File content format and/etc/crontab similar
Time notation:
*: Each time point in the valid value range of the time point;
-: A specific continuous time range, 3-7
,: A discrete point in time, 3,5,7
/#: The amount of time in a valid time frame, for specifying the frequency;
For user cron Tasks, it is recommended to use the crontab command
crontab [-u user] [-l |-r |-e]
-u User: Not to manage your own cron task, but to specify the target user's cron task; Root has the ability to manage other users ' cron tasks; default management of their own;
-l:list, list the tasks;
-r:remove to remove all tasks;
-e:edit, edit, open a default editor for the current shell session to edit the cron task table;
Anacron: In days or after the boot immediately after the Anacron action, he will go to detect the downtime should be carried out but did not do the cron service, if there is the task to execute once, and then automatically stop.
(1) If you do not want to receive notification messages for task execution results:
COMMAND >/dev/null
COMMAND &>/dev/null
(2) for crontab file,% has a special function, if the command will appear in the%, remember to escape, or use single quotation marks to its reference;
(3) Crontab's path variable is not exactly the same as the user's variable, so it is recommended that the task in cron use an absolute path

2, every Monday to Saturday 3:20 A.M., run the CP command to archive the/etc/directory, storage location is/BACKUPS/ETC-YYYY-MM-DD;


3 * * 1-6/bin/mkdir-p/backups/"etc-" '/bin/date +\%y-\%m-\%d ' &&/bin/cp-rf/etc/* "$_"

650) this.width=650; "Width=" 793 "height=" "title=" 1.png "style=" width:548px;height:55px; "alt=" Wkiom1xunvpguzvxaack9pextja996.jpg "src=" Http:// "/>

650) this.width=650; "title=" 2.png "alt=" wkiol1xun2tcw4k_aatg5jpjpso999.jpg "src=" 72/d0/wkiol1xun2tcw4k_aatg5jpjpso999.jpg "/>

3, every Sunday 2:30 A.M., run the CP command to backup the/etc/fstab file, the storage location is/BACKUP/FSTAB-YYYY-MM-DD-HH-MM-SS;

2 * * 7/bin/mkdir-p/backup/"fstab-" '/bin/date +\%y-\%m-\%d\-%h-\%m-\%s ' &&/bin/cp-rf/etc/fstab "$_"

4, every night 12 o'clock, get all the lines in the/proc/meminfo file starting with S or M, appended to the/statistics/meminfo.txt file, and the daily message before, to add a similar =============== separator line;

Create script:

echo "============================" >>/statistics/meminfo.txt
grep ^[SM]/proc/meminfo >>/statistics/meminfo.txt

650) this.width=650; "title=" 1.png "style=" Float:none; "src=" Wkiol1xu5kej1t9taactf12-6pa170.jpg "alt=" Wkiol1xu5kej1t9taactf12-6pa170.jpg "/>


0 0 * * */test/

650) this.width=650; "title=" 2.png "style=" Float:none; "src=" Wkiol1xu5kedp9ozaaad2ln6eiu782.jpg "alt=" Wkiol1xu5kedp9ozaaad2ln6eiu782.jpg "/>

650) this.width=650; "title=" 3.png "src=" Http:// " alt= "Wkiol1xu5m6qqpujaah3davryyw643.jpg"/>

This article is from the "^ Fox tail $" blog, so be sure to keep this source

Linux OPS-Scheduled Tasks (September 5)

Related Article

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: 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.