linux-Basic Knowledge

Source: Internet
Author: User

Linux Task Scheduler, recurring task execution


Perform one task at a time in the future: at, Batch

To run a task periodically: cron


e-Mail Service:

Smtp:simple Mail Transmission protocol for sending mail;

Pop3:post Office Protocol

Imap4:internet Mail Access Protocol


Mailx-send and receive Internet mail


Mua:mail User Agent


MAILX [-S ' SUBJECT '] username[@hostname]

The message body is generated:

(1) give directly, Ctrl+d;

(2) input redirection;

(3) through the pipeline;

Echo-e "How is you?\nhow old is you?" | Mail


Mailx


AT command:


At [option] Time


Time:

hh:mm [YYYY-MM-DD]

Noon, midnight, teatime

Tomorrow

Now+#{minutes,hours,days, or weeks}


Common options:

-Q QUEUE:

-L: Lists jobs waiting to be run in the specified queue; equivalent to ATQ

-D: Deletes the specified job; equivalent to ATRM

-C: View specific job tasks;

-f/path/from/somefile: Reads the task from the specified file;


Note: The execution results of the job are notified to the relevant users by email;


Batch command:

Allow the system to choose its own idle time to perform the tasks specified here;


Recurring Task Scheduler: Cron

Related packages:

Cronie: The main package, provides the Crond daemon and related auxiliary tools;

Cronie-anacron:cronie to monitor the execution of Cronie tasks, such as when a task in Cronie has not run correctly in the past, the Anacron will then initiate this task;

Crontabs: Includes centos to provide system maintenance tasks;


Make sure that the Crond daemon is in a running state:

CentOS 7:

Systemctl Status Crond

..... running ...

CentOS 6:

Service Crond Status


The tasks that are scheduled to be performed periodically are submitted to Crond, which is implemented to the point of operation.

System Cron Task: system maintenance Job

/etc/crontab

User Cron Task:

crontab command


System Cron Task

# 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


Example: Run the echo command at 9:10 in the evening;

* * * * Gentoo/bin/echo "howdy!"


Time notation:

(1) a specific value;

A value in the range of valid values for a given point in time;

(2) *

All values in the range of valid values at a given point in time;

means "every ...";

(3) Discrete value:,

#,#,#

(4) Continuous value:-

#-#

(5) in the specified time range, define the step size:

/#: #即为步长


Example: Echo command every 3 hours;

0 */3 * * * gentoo/bin/echo "howdy!"


User cron:

crontab command definition, each user has a dedicated cron task file:/var/spool/cron/username


crontab command:

crontab [-u user] [-l |-r |-e] [-I.]

-L: Lists all tasks;

-E: Editing tasks;

-R: Remove All Tasks;

-I: Used in conjunction with-R to allow users to selectively remove assigned tasks in interactive mode;


-U User: Only root can run, on behalf of the designated users to manage cron tasks;


Note: The results of the operation are notified to the relevant users by email;

(1) COMMAND >/dev/null

(2) COMMAND &>/dev/null


For cron tasks,% has a special purpose, and if you want to use% in a command, you need to escape, but if you put% in single quotes, you can not escape;


Thinking:

(1) How do I run a task at the second level?

* * * * * for min in 0 1 2; Do echo "HI"; Sleep 20; Done

(2) How do I run a task every 7 minutes?


Sleep command:

Sleep Number[suffix] ...


SUFFIX:

S: seconds, default

M: minutes

H: Hours

D: Day



Linux system service Management

Chkconfig--list

Chkconfig--level 3 Network off

Chkconfig--level 345 Network off

Chkconfig--del Network

Chkconfig--add Network


Linux system service Management-SYSTEMD

Systemctl list-units--all

SYSTEMCLT list-units--type=service

A few common service-related commands:

Systemctl Enable Crond.service

Systemctl Disable Crond.service

Systemctl Status Crond.service

Systemctl Stop Crond.service

Systemctl Start Crond.service

Systemctl Restart Crond.service

Systemctl is-enabled Crond.service


[Email protected] ~]# ls-l/etc/systemd/system/multi-user.target.wants/crond.service

lrwxrwxrwx. 1 root root 37 July 05:45/etc/systemd/system/multi-user.target.wants/crond.service-/usr/lib/systemd/system/ Crond.service


Linux system service Management-SYSTEMD

Ls/usr/lib/systemd/system # #系统所有unit, divided into the following types

Service System Services

Target multiple units consisting of groups

Device hardware devices

Mount File System mount point

AutoMount Automatic mount point

Path file or path

Scope is not an external process initiated by SYSTEMD

Slice Process Group

Snapshot Systemd Snapshot

Socket inter-process communication sockets

Swap file

Timer Timer


Operating level:

ls/usr/lib/systemd/system/runlevel*


Liunx System service Management-SYSTEMD

1.unit Related commands

Systemctl list-units//list the running unit

Systemctl list-units--all//list all, including all failed or inactive

Systemctl list-units--all--state=inactive//list inactive unit

Systemctl list-units--type=service//list service with Active status

Systemctl is-acvive Crond.service//See if a service is active


System to manage unit with target for ease of management

Systemctl List-unit-files--type=target

Systemctl list-dependencies multi-user.target//See which unit is under the specified target

Systemctl Get-default//view system default target

Systemctl Set-default Multi-user.target

A service belongs to one type of unit

Multiple unit consists of a target

A target contains multiple service

Cat/usr/lib/systemd/system/sshd.service//Look at the Install section





linux-Basic Knowledge

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.