Linux scheduled crontab execution (1)

Source: Internet
Author: User

Crontab-e

Enter a vi editing interface

Add

*/30 * netstat>/tmp/net. log

The netstat command is executed every 30 minutes and the execution result is saved to net. log.

Crontab is a program that conveniently executes a task in a scheduled (Cyclic) manner on unix/linux systems.

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 crond as a service automatically started after the system starts. You can add

Service crond start

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

For example, service mysqld start

Basic usage:

1. crontab-l

List the current crontab task

2. crontab-d

Delete the current crontab task

3. crontab-e (crontab-r above solaris5.8)

Edit a crontab task and ctrl_D ends.

4. crontab filename

Use filename as the crontab task list file and load it

Crontab file format:

Rows in the crontab file are composed of six fields. Different fields are separated by spaces or the tab key. The first five fields specify the time when the command will be run.

Minutes (0-59)

Hour (0-23)

Date (1-31)

Month (1-12)

Day of the week (0-6, 0 indicates Sunday)

The 6th fields are strings to be executed at the appropriate time

Example:

# MIN HOUR DAY MONTH DAYOFWEEK COMMAND

#06:10 every morning

10 6 **** date

# Every two hours

0 */2 *** date (solaris 5.8 does not seem to support this method)

# Every two hours from PM to am, am

0 23-7/2, 8 **** date

# Am on the 4th day of each month and from Monday to Wednesday of each week

0 11 4 * mon-wed date


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.