Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure timing tasks in Linux system

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to configure Linux system timing tasks". In daily operation, I believe many people have doubts about how to configure Linux system timing tasks. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to configure Linux system timing tasks". Next, please follow the editor to study!

One: definition

Crond is a service or software used in Linux system to execute commands or specify program tasks on a regular basis.

1. Tasks regularly performed by the linux system itself (polling system logs, backing up data, etc.)

2. Tasks performed by users (regularly updating synchronization time, website data backup, etc.)

Two: command syntax

The command for a scheduled task is crontab, and its daemon is crond (the program that the service is running)

Crontab [- u users] file

Crontab [- u users] [- e |-l |-r]

-e Editing scheduled tasks

-l View scheduled tasks

-r clear scheduled tasks

/ etc/cron.deny (allow) controls authorized users who use crontab

/ etc/spool/cron/ where all users' crontab profiles are stored

Three: system timing task format

[root@Centos ~] # cat / etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

# For details see man 4 crontabs

# 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

/ etc/crontab is divided into seven segments, separated by spaces, and user segments are 6.

Time format: time-sharing, day, month and week-- * user-name command

The meaning of special symbols

* any (per 'time')

-(minus sign) separator, indicating that a period of time means "to" as in tables 17-19.

, (comma) separate periods, two discontiguous times

/ n (n for numbers) time per N units, / 5 per 5XX

Four: service status check

Chkconfig-- list crond to check whether the service is powered on

[root@Centos] # chkconfig-- list crond

Crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@Centos ~] # ps-ef | grep crond to check whether the service is started

[root@Centos ~] # ps-ef | grep crond

Root 1746 1 0 09:17? 00:00:01 crond

Root 2274 2052 0 10:14 pts/0 00:00:00 grep crond

/ etc/init.d/crond start (restart) start and restart the service

Fifth, the writing specification of scheduled tasks (production environment)

1. Some annotated information must be added to the writing of scheduled tasks.

2. Add / bin/sh before executing the shell script task

3. Execute related tasks under the specified user, batch script (echo "script rules" > > / var/spool/cron/root)

4. Add > dev/null 2 > & 1 to the end of the scheduled task (script task) to throw some unnecessary output information (error or standard output) into the empty device, that is, the default does not output unnecessary information.

Redirect

> or 1 > output redirection (correct result) > > or 1 > >

2 > or 2 > error redirection (result of error)

/ server/log/name.log

[root@Centos log] # date

Wed Aug 24 10:57:17 CST 2016

[root@Centos log] # cat / server/log/name.log

Name

Name

[root@Centos log] # date

Wed Aug 24 10:58:18 CST 2016

[root@Centos log] # cat / server/log/name.log

Name

Name

Name

Test that this scheduled task has been executed successfully

2. On Saturdays and Sundays, the script / server/scrpts/name.sh is executed every Saturday and Sunday. The content of the script is to print the date of the day and append it to a file at will.

Write this scheduled task step by step according to the writing specification

Script content

Date F > > name.txt

Edit script

Vi name.sh

Date F > > name.txt

The script executes the test in full path

/ bin/sh / server/scrpts/name.sh

Writing timing task

09pr 14 * * 6pr 7 / bin/sh / server/scrpts/name.sh

Edit scheduled task file

Crontab-e

# one shell by yuw001 2016-08-10

0914 * * 6 bin/sh 7 / server/scrpts/name.sh > dev/null 2 > & 1

At this point, the study on "how to configure the timing tasks of the Linux system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report