Linux Autorun Script Parameters Introduction

Source: Internet
Author: User
Tags php script

Debian's timed execution command crontab
2012-12-3 5:50 Category: NAS 2743 views 1 reviews Tags:LinuxDebian
Debian's timed execution command crontab, which corresponds to a scheduled task for Windows
If you want Debian to execute commands on a regular basis, crontab!
It functions like Microsoft's scheduled tasks and can execute the commands you want at the time you set.
By writing a setup file, you can combine complex execution times to make the execution of the command more efficient.
The location of the cron settings file under the Debian system
/etc/crontab
The general contents are as follows:
01
#/etc/crontab:system-wide Crontab
02
# Unlike any and crontab you don ' t has to run the ' crontab '
03
# command to install the new version when you edit this file.
04
# This file also have a username field, that's none of the other crontabs do.
05

06
Shell=/bin/sh
07
Path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
08

09
# m H Dom Mon Dow user command
10
* * * * * Root run-parts--report/etc/cron.hourly
11
6 * * * Root test-x/usr/sbin/anacron | | Run-parts--report/etc/cron.daily
12
6 * * 7 root test-x/usr/sbin/anacron | | Run-parts--report/etc/cron.weekly
13
6 1 * * Root test-x/usr/sbin/anacron | | Run-parts--report/etc/cron.monthly
14
0 1 * * root/usr/bin/updatedb
15
#
What you need to set is the # m H Dom Mon Dow user command section below
The corresponding meaning from left to right is:
0-59 hours 0-23 Days January-3 January 1-12 weeks 0-7 user commands for executing commands


One of the more interesting is: week, 0 and 7 are all on behalf of the Sunday
and the special symbols that can be used are
* (asterisk) represents all time accepted
, (comma) represents the number of values that the same classification can have
-(minus sign) represents the execution during this time period
/n represents once every n times
Example:
* * * command: <em> daily 12:30 Execution command</em>
0 6,12 * * command:<em> 6:00 and 12:00 per month of 15th, executed command</em>
8 1-15 6 * command:<em> per year June 1 to 15th 8:10 execution command</em>
*/5 * * 7 command: <em> Sunday command</em> every five minutes
Timer Syntax:
Is the first part of the above-planned task. It determines when to execute a scheduled task.
It consists of 5 parts:
1. Minutes (0-59)
2. Hours (0-23)
3. What day of one months (1-31)
4. Which month of the year (1-12)
5. Day of the week (0 is Sunday)
Asterisks if a section appears with an asterisk instead of a number, it means that the time represented by this part is all performed.
It may not be easy to speak clearly at the moment, so look at the example.
Example:
1, the following scheduled tasks will continue to run
* * * * * * [command]
2. The following scheduled tasks will run at 0 ticks per hour (that is, hourly execution)
0 * * * * [command]
3. The following is still a scheduled task that runs hourly. But it runs at a quarter of an hour (1:15,2:15 ... )
* * * * * [command]
4, the following scheduled tasks are performed once a day, at 2:30 minutes
2 * * * [command]
5. The following scheduled tasks are performed at midnight 2nd on each month (for example: February 2, 2010 00:00)
0 0 2 * * [command]
6. The following scheduled tasks will be performed at 0 minutes per hour every Monday
0 * * * 1 [command]
7, the following will run 3 times per hour, in 0 minutes, 10 points, and 20 ticks
0,10,20 * * * * [command]
8, the following is used division sign "/" to indicate how many times each run.
*/5 * * * * [command] runs every 5 minutes
*/2 * * * [command] run every 2 hours (* */2 * * * [command] this is wrong! )
*/1 * * * * root wget-o/var/log/cron.txt http://www.592.net/test.php every minute to visit a PHP script, check if PHP is automatically running every minute, can view Var/log/cro N.txt file, see if there is a website PHP back to the content on it!
9, you can also use "-" to indicate a range, as follows 5 to 10 points of each hour to run
0 5-10 * * * [command]
10, there is also a special time keyword "@reboot", that is, each time you restart the server to run a scheduled task
@reboot [command]

Set up and manage scheduled tasks
Edit Crontab to set up a scheduled task. Using the following command, the crontab content is opened in VI for editing:
Crontab-e
If you only want to see and do not need to edit, you can use the following command
Crontab-l
To delete the contents of the crontab, delete all the scheduled tasks, so you can:
Crontab-r

Cron is a timed execution tool under Linux that can run a job without human intervention. Since Cron is a built-in service for Linux, he does not automatically get up and can start and close the service in the following ways:


Edit/etc/crontab File Configuration cron
Cron service every minute not only to read all the files within/var/spool/cron, but also to read a/etc/crontab, so we configure this file can also use the Cron service to do something. The crontab configuration is for a user, while the edit/etc/crontab is a task for the system. The file format for this file is:
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root//If an error occurs, or if there is data output, the data is sent to this account as an email
home=///user-run path, here is the root directory
# Run-parts
* * * * * root run-parts/etc/cron.hourly//hourly execution of scripts within/etc/cron.hourly
4 * * * Root run-parts/etc/cron.daily//daily execution of scripts within/etc/cron.daily
4 * * 0 root run-parts/etc/cron.weekly//weekly execution of scripts within/etc/cron.weekly
4 1 * * Root run-parts/etc/cron.monthly//monthly to execute scripts within/etc/cron.monthly
Attention to the "run-parts" This parameter, if you remove this parameter, you can later write to run a script name, not the folder name.


Restart command:
Debian
/etc/init.d/cron restart
Linux
/etc/rc.d/init.d/crond restart

Linux Autorun Script Parameters 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.