34. Linux System Task Scheduler cron, chkconfig Tools, SYSTEMD Management Services, Unit introduction

Source: Internet
Author: User

34. Linux System Task Scheduler cron, chkconfig Tools, SYSTEMD Management Services, Unit introduction, Target introduction

I. Linux system Task Scheduler cron

crontab command: Use this command for the operation of the task scheduling feature. Options:

-U: Specifies that a user, without-u, is the current user.

-E: Make a task plan.

-L: Lists the task schedule.

-R: Deletes the task schedule.

Configuration file for Task Scheduler:/etc/crontab

There are five fields in a file.

From left to right: minutes, hours, days, months, weeks, users, commands.

You can not specify that the user is root.

# CRONTAB-E//write a task plan, the actual use of Vim opened the crontab configuration file.

The /var/spool/cron/username of the configuration file that is opened at this time. (If the user is root, then cron is root). can not VI edit this file, can only be edited with crontab-e , otherwise error.

* denotes all. such as weekly, daily, monthly.

0 3 * * */bin/bash/usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log

For example, execute a script.

Each field can write a range:

0 3 1-10 */2 2,5/bin/bash/usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log

1-10 days, divisible by 2 months, Tuesday and Friday

# Systemctl Start Crond starting the Crond service, to use the Task Scheduler, it will start.

# PS aux |grep cron

Root 589 0.0 0.0 126236 1612? Ss 01:51 0:00/usr/sbin/crond-n

Root 1460 0.0 0.0 112676 980 pts/0 s+ 04:26 0:00 grep--color=auto cron

This process indicates that the service has been started.

# SYSTEMCTL Status Crond view its status and if it starts, it displays the green active (running). If it does not start, no font has color display, inactive (dead).

in the configuration file Command writes absolute path when writing a task plan , otherwise it may not be performed because it is not in the environment variable.

Each time you write a task plan, the correct log and error log are appended to the save. When something goes wrong, it can be traced.

Second, Linux system service management-chkconfig

The Service Management tool on CENTOS6 is chkconfig, and all of the preset services in the system can be seen through/ETC/INIT.D. Centos7 no longer extends CENTOS6 's service management program anymore. So there are only a few files.

# LS/ETC/INIT.D all pre-set service directories

Functions Netconsole Network README

# chkconfig--list List all services and their opening status at each level

Note: This output shows only the SysV service and does not contain

Native SYSTEMD services. SysV Configuration Data

May be overwritten by native SYSTEMD configuration.

To list the SYSTEMD service, execute ' systemctl list-unit-files '.

To view the services enabled on the specific target, perform

' Systemctl list-dependencies [target] '.

Netconsole 0: Off 1: Off 2: Off 3: Off 4: off 5: off 6: Off

Network 0: Off 1: Off 2: Open 3: Open 4: Open 5: Open 6: Off

CENTOS6 and formerly SYSV service Management, CENTOS7 is SYSTEMD service management.

Level: System boot level (usage prior to 7, 7 not strictly level sensitive)

0: Shutdown status.

1: Single-user mode

2: Less than 3 one NFS service

3: Multi-user mode with no graphics

4: Reserved state, custom for user

5: Multi-user mode with graphics

6: Restart

# chkconfig--level 3 Network off

--LEVEL Specifies the level, then the service name, then off or on.

You can also specify multiple levels,--level 345.

You can also omit the level, which defaults to 2, 3, 4, and 5 operations.

Services must be in the/etc/init.d/directory to add services.

Add service, Chkconfig--add Network (service name)

Delete Service, Chkconfig--del Network

Can be found in Chkconfig--list.

In-file format these two points must have, otherwise unrecognized

# chkconfig:2345 10 90

# description:activates/deactivates all network interfaces configured to \

# start at boot time.

Third, SYSTEMD Management services

# systemctl list-units--all--type=service list system all services

Common commands:

# Systemctl enable Crond to enable a service to boot (. Service can be omitted)

# systemctl Disable crond do not let service boot up

# SYSTEMCTL Status Crond view service status

# Systemctl Start Crond start a service

# Systemctl Stop Crond Stop a service

# systemctl Restart Crond restart a service

# systemctl is-enabled crond Check if a service is booting

Iv. introduction of the unit

# Ls/usr/lib/systemd/system There are a number of files, categorized into the following categories:

Service: System Services

Target: A group of more than one unit

Device: Hardware Device

Mount: File system mount point

AutoMount: Automatic mount point

Path: File or Path

Scope: External process not initiated by SYSTEMD

Slice: Process Group

Snapshot:systemd Snapshot

Socket: Socket for interprocess communication

Swap:swap file

Timer: Timer

Each type of file is a unit, and it is these units that make up the various resources of the system (individual services, individual devices, etc.)

Unit-related commands:

# systemctl List-units//list the unit that is running (active)

# Systemctl List-units--all//list all unit (including failed, inactive)

# systemctl list-units--all--state=inactive //List all inactive's unit

# systemctl List-units--all--type=service//List all status of service

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

# Systemctl Is-active crond.service//See if a unit is active

Five, Target introduction

Similar to the boot level in CENTOS6, Target supports multiple simultaneous booting. It is a combination of multiple unit, the system starts is to start a number of unit,target is used to manage these unit.

# Systemctl List-unit-files--type=target//View all target of current system

# Systemctl List-dependencies multi-user.target//View a target contains all the unit, in a tree-shaped column.

# Systemctl Get-default//view system default target

# Systemctl Set-default multi-user.target//set default target

Connection between service, unit, and Target:

1) A service belongs to a unit

2) Multiple unit together to form a target

3) A target contains multiple service that can view the contents of the [Install] section of the file/usr/lib/systemd/system/sshd.service, which defines which target the service belongs to.


34. Linux System Task Scheduler cron, chkconfig Tools, SYSTEMD Management Services, Unit introduction

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