September 5, 2015 Course assignments (practice)

Source: Internet
Author: User
Tags create directory

1. Summarize the detailed usage method of the task plan (at, crontab) on Linux system;

AT command:

To host a job that runs in the future time:

Support for using job queues:
The default is a queue;

Ctrl+d

At [option] ... Time

Time:
(1) Absolute time
HH:MM,
Mmdd[cc]yy, Mm/dd/[cc]yy, dd.mm.[cc]yy or [cc]yy-mm-dd
Tomorrow
(2) Relative time
now+ #UNIT
Minute, hour, day, week
(3) Blur time
Midnight
Noon
Teatime

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


=============================================================================================================

Crontab: Recurring Task Schedule


Daemon: Crond

There are two types of recurring tasks:
(1) System cron task; There is no default running user identity, so you need to specify the additional runner;
/etc/crontab

Vim command

# Example of Job definition:
#.----------------Minute (0-59)
# | .-------------Hour (0-23)
# |  | .----------Day of Month (1-31)
# |  |  | .-------month (1-12) OR jan,feb,mar,apr ...
# |  |  |  | .----Day of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# |  |  |  | |
# * * * * * * user-name command to be executed

                     7 fields:    
                         Top 5 fields: Point in time    
                         User-name: Run tasks as a user    
                         command to being executed: To run the task            

(2) User Cron Task: Submitted by a user, the default is to run as the submitter, so there is no need to specify the additional runner;
/var/spool/cron/username

VIM command; not recommended
crontab Command: Recommended

# Example of Job definition:
#.----------------Minute (0-59)
# | .-------------Hour (0-23)
# |  | .----------Day of Month (1-31)
# |  |  | .-------month (1-12) OR jan,feb,mar,apr ...
# |  |  |  | .----Day of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# |  |  |  | |
# * * * * * command to be executed

                     5 time points:    
                         minutes: Valid range of values 0-59;    
                         hours: 0-23    
                         Day: 1-31    
                         Month: 1-12    
                         weeks: 0-7

Note: The date of the month and the number of weeks, not recommended to use at the same time;

For example:
6 * * * *


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;
1-30/4, */4

5 */3 * * */bin/echo "howdy"

5 7 * * 1-5/bin/echo "Howdy"

                     crontab command:    
                         crontab [-u user] [-l |- R | -e]    
                            -u User: Not managing your own cron task, but specifying the target user's cron task ; Root only has permissions to manage other users ' cron tasks; The default is to manage 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;

Attention:
(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
/root/bin/a.sh

=============================================================================================================== ======

Practice:

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

[[email protected] ~]# mkdir/backups///Create Directory

[Email protected] ~]# Echo 3 * * 1-6/bin/tar-cvf/backups/ect-$ (date +%f). Tar "/etc >>/var/spool/cron/roo T

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

[[email protected] ~]# echo "3 * * 1-6/bin/cp-a/etc/backups/ect-$ (date +%f)/" >>/var/spool/cron/root

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

[Email protected] ~]# echo "2 * * 0/bin/tar-cvf/backups/fstab-$ (date +%f-%h-%m-%s). Tar"/etc/fstab >>/va R/spool/cron/root

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;

[Email protected] ~]# mkdir statistics

[Email protected] ~]# crontab–e

Save exit after editing the following content
0 0 * * * echo-e "====================\n" + ' egrep ' ^[sm] '/proc/meminfo ' >>/statistics/meminfo.txt

650) this.width=650; "title=" Image_thumb1 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" Image_ THUMB1 "src=" http://s3.51cto.com/wyfs02/M02/72/CD/wKiom1XtXKPD5ql-AAC7uRNCSks850.jpg "height=" 136 "/>

September 5, 2015 Course assignments (practice)

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.