Linux Timer Program-crontab

Source: Internet
Author: User
Tags apache access log

Crontab is a convenient way to regularly (cyclically) execute a task on Unix/Linux systems.Program

Use the cron service and use the service crond status to view the cron service status. If it is not started, the Service crond start starts it,

The cron service is a regular execution service. You can use the crontab command to add or edit tasks that require scheduled execution:

Crontab-u // set a user's cron service. Generally, the root user needs this parameter when executing this command.

Crontab-l // list the details of a user's cron Service

Crontab-r // Delete the cron service of no user

Crontab-E // edit a user's cron Service

For example, to view your cron settings as root: crontab-u root-l

For another example, Root wants to delete Fred's cron settings: crontab-u Fred-R

When editing the cron service, the edited content has some formats and conventions. Enter crontab-u root-e.

In VI editing mode, the edited content must conform to the following format: */1 ***** ls>/tmp/ls.txt

Edit the/etc/crontab file and add a line at the end: 30 5 * root init 6 so that the system is configured to automatically restart at every morning.

You need to set crondServices automatically started after the system startsIn/etc/rc. d/rc. Local, add

Service crond start

If you need to load other services when the system starts, you can continue to add the startup commands for other services.

For example, service mysqld start

 

Format:

Each row of the crontab file consists of six fields (Minutes, hours, day of month, month, day of week, command)Fields are separated by spaces or tabs:

Minutes: minute field. The value ranges from 0 to 59.

Hours: small time domain. The value ranges from 0 to 23.

Day of month: date. The value ranges from 1 to 31.

Month: month. The value ranges from 1 to 12.

Day of week: day of the week. The value ranges from 0 to 6. The value of Sunday is 0.

Command: the command to be run

 

If a domain is *, the command can be executed within all possible values of the domain.

If a field is two numbers separated by a hyphen, the command can be executed within the range of two numbers (including the two numbers themselves ).

If a field is composed of a series of values separated by commas, the command can be executed within the range of these values.

If both the date and week fields have values, these two fields are valid.

 

For example

An Apache access log file is named access_log. Write a shell script to output all the lines in the log containing the IP address 10.3.136.75 to a new file named 75log, and add it to the scheduled task.

Crontab-e

Join

(Every two hours from PM to am, am)

* 11-7/2, 8 *** grep access_log 10.3.136.75> 75log

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.