How to write __linux under Linux crontab

Source: Internet
Author: User
Tags memory usage

The function of the crontab command is to schedule the execution of some commands at certain intervals. In the/etc directory there is a crontab file, where there are some scheduling programs running on the system. Each user can establish their own scheduling crontab.

The primary configuration file for Cron is/etc/crontab, which includes the following lines:

    Shell=/bin/bash
            PATH =/sbin:/bin:/usr/sbin:/usr/bin
            mailto= Root
            home=/
             # run-parts
             * * * Root run-parts/etc/cron.hourly
             4 * * * Root run-parts/etc/cron.daily
             4 * * 0 root run-parts/etc/cron.weekly
             4 1 * * Root run-parts/etc/cron.monthly

The first four lines are variables used to configure the Cron task's running environment. The value of the shell variable tells the system which shell environment to use (in this case, the bash shell); The path variable defines the paths used to execute the command. The output of the cron task is mailed to the user name defined by the MAILTO variable. If the MAILTO variable is defined as a blank string (mailto= ""), the e-mail message is not sent. The home variable can be used to set the master directory to use when executing commands or scripts.

Each row in the/etc/crontab file represents a task, and its format is:

Minute   hour   Day   month   DayOfWeek   command

minute-minutes, any integers from 0 to 59

hour-hours, any integer from 0 to 23

day-date, any integer from 1 to 31 (if a month is specified, it must be a valid date for that month)

Month-month, any integer from 1 to 12 (or the English abbreviation for the month used, such as the long, Feb, etc.)

Dayofweek-week, any integer from 0 to 7, where 0 or 7 represent Sunday (or use the English shorthand for the week, such as sun, Mon, etc.)

command-commands to execute (commands can be commands such as Ls/proc >>/tmp/proc, or commands that execute scripts you write yourself.) )

In any of these values, the asterisk (*) can be used to represent all valid values. For example, the asterisk in the month value means that the command is executed every month after other constraints are met.

A dash (-) between integers specifies a range of integers. For example,1-4 means integers 1, 2, 3, and 4.

Specify a list with a series of values separated by commas (,). For example,3, 4, 6, 8 indicate these four specified integers.

The forward slash (/) can be used to specify the interval frequency. Adding /<integer> after a range means that you can skip integers within the range. For example,0-59/2 can be used to define every two minutes in the minute field. The interval frequency value can also be used with the asterisk. For example, a*/3 value can be used in the month field to indicate that a task is run every three months.

The line that starts with the pound sign (#) is a comment and is not processed.

As you can see in the/etc/crontab file, it uses Run-parts scripts to perform/etc/cron.hourly,/etc/cron.daily,/etc/cron.weekly, and/etc/cron.monthly Scripts in the directory, which are executed hourly, daily, weekly, or monthly. The files in these directories should be shell scripts.

A cron task can be added to the/ETC/CRON.D directory if it needs to be executed according to schedule instead of hourly, daily, weekly, or monthly. All files in the directory use the same syntax as in/etc/crontab.

# The memory usage of the system every Monday # at 3:30AM in the
            file/tmp/meminfo
            3 * * Mon cat/proc/m Eminfo >>/tmp/meminfo
            # Run custom Script the "a" of every month at 4:10am
            4 1 * */root/scripts/b ackup.sh

Be careful to add permissions and paths while writing the. sh script executed by crontab. For example:

Crontab statement: * * */opt/apps/ems_query/bin/start.sh

The appropriate script:

Source/home/tvgame/.bash_profile
cd/opt/apps/ems_query/bin/

Java-xmx64m-jar.. /lib/ems_query.jar &


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.