Linux Task Scheduler cron, chkconfig Tools, SYSTEMD Management, Unit introduction, Targe Introduction

Source: Internet
Author: User

Linux Task Scheduler Cron

Linux Task Scheduler: Automatically executes commands or scripts at a certain time.

Configuration file for Task Scheduler
cat /etc/crontab

The first two lines are defined variables, the third line is to send the message to whom, and then the last line has five * (asterisks) corresponding to five bits, that is, the above five elements, the following to explain what the difference means:

1. Indicates minutes (0-59)

2. Indicates hours (0-23)

3. Presentation date (1-31)

4. Indicates the month (1-12 can be written in digits or abbreviated in English)

5. means the week (0-6,0 or 7 means Sunday, also can be written in English shorthand)

The end of the last line is the user (the root user does not write the default is root)

The next section, where COM begins, is the command you want to execute.

Custom Task Scheduler (usage and VIM)
crontab -e

Case: Execute 123.sh script at 3 points per day (asterisks are all, for example, the third means that 1-31 days are executed)
0 3 * * * /bin/bash /usr/local/sbin/123.sh

Output the correct results and the wrong results in 123.log
0 3 * * * /bin/bash /usr/local/sbin/123.sh >/tmp/123.log 2>/tmp/123.log

Add the correct results and the wrong results to 123.log
0 3 * * * /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log

The Tuesday and Friday three points of 1-10, every two months, can be written in the following format. 0 is the minute, 3 is the hour, 1-10 is the date 1th to 10th, the asterisk/2 is the month divided by 2, 2,5 is the month of Tuesday and Friday
0 3 1-10 */2 2,5

After Setup we also need to start cron with the Systemctl start Crond command to enable the schedule.
systemctl start crond

See if scheduling is enabled
ps aux |grep crom

Or use Systemctl start Crom (Crom is your plan name, the red one in the picture is the plan name)
systemctl start crom

(green means already enabled)

Sometimes the execution script is scheduled, but the execution is probably not using an absolute path, and the solution either adds the path to the command in the plan or uses an absolute path.

There is also the suggestion that the scheduled tasks should be written with the correct and incorrect results appended to a file in order to ensure that the task is well documented.

-l list, view the list of scheduled tasks
crontab -l

Task Scheduler cron files in /var/spool/cron/ directory, if Root cron is/ var/spool/cron/root (cat view)

-R Delete Schedule
crontab -r

-U Specify user
crontab -u root -l(Specify a task plan to view root)

Chkconfig Service Management Tools

Chkconfig Service management tools (mainly used in CENTOS6 and previous systems, such as how to control service startup, how to control service start-up, how to control service startup at a specified level, etc.)

View services using Chkconfig in the current system (only the process of SYSV service Management mode is listed, Centos7 many are systemd mode)
chkconfig --list

Use the command above in Centos7 to see only two services, such as

The two process files are in the following path (after which we can put the script into this directory with Chkconfig tool management is also possible)
ls /etc/init.d/

Indicates what state the service is in at level 0-6, boot or shutdown (network is the service name that needs to be shut down or turned on, off is on)
chkconfig network off

Linux Task Scheduler cron, chkconfig Tools, SYSTEMD Management, Unit introduction, Targe Introduction

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.