Detailed and Linux examples in the crontab
cron is a regular implementation tools under linux, you can without human intervention to run operations. Cron is a Linux built the service, but it does not automatically up, you can use the following methods to start, shut down the service:
/ Sbin / service crond start / / start the service
/ Sbin / service crond stop / / close service
/ Sbin / service crond restart / / restart the service
/ Sbin / service crond reload / / reload the configuration
You can also start the service automatically when the system starts:
In / etc / rc.d / rc.local add at the end of this script:
/ Sbin / service crond start
Cron is now inside the service has been in the process, we can use the service a, Cron service provides the interface for people to use the following:
1, directly edit the crontab command
cron service providers to set the cron crontab command service, the following are some of the parameters of this command and description:
crontab-u / / Set a user's cron service, usually root user to execute this command when the need for this parameter
crontab-l / / a user cron services listed in the details
crontab-r / / delete a user's cron service
crontab-e / / edit a user's cron service
For example, set the root view your cron: crontab-u root-l
As another example, root want to delete the cron setting fred: crontab-u fred-r
Cron service in the edit, edit, format and content of some conventions, type: crontab-u root-e
Enter vi edit mode, edit the content must meet the following format: * / 1 * * * * ls>> / tmp / ls.txt
This format is the first part of the time setting, followed by part of the command to execute if the command to execute too many commands can write a script inside, and then to go ahead and call this script on it, call When I remember to write the full path of the command. Set the time we have some agreement, in front of five * indicates five numbers, numbers, scope and meaning of values as follows:
Week (0-6) / / 0 for Sunday
In addition there are several a number of special symbols is "*","/" and "-",",",* on behalf of all the figures within the range, "/" represents the meaning of each "* / 5 "that every 5 units," - "represents a number from one figure to," "a few discrete separate figures. The following few examples illustrate the problem:
6 o'clock every morning
0 6 * * * echo "Good morning.">> / Tmp / test.txt / / Note that a simple echo, not see any output from the screen, because the cron to email to any output is the root of the mailbox.
Every two hours
0 * / 2 * * * echo "Have a break now.">> / Tmp / test.txt
11 pm to 8 am every two hours between the morning and eight o'clock
0 23-7/2, 8 * * * echo "Have a good dream:)">> / tmp / test.txt
4 of each month and each week Monday to Wednesday morning 11
0 11 4 * 1-3 command line
January 1 4:00 am
0 4 1 1 * command line
Each time a user's cron editing settings, cron automatically in / var / spool / cron generate a file with this user the same name, the user's cron messages are recorded in the file, this file can not be edited directly , only can use crontab-e to edit. cron started reading once every minute over a file, check if you want to execute the command inside. Therefore, this file does not need to restart the modified cron service.
2, edit / etc / crontab file configuration cron
cron service not only to read once per minute / var / spool / cron all files, also need to read a / etc / crontab, so we can configure this file using cron service to do something. Crontab configuration is used for a user, and edit / etc / crontab is the task for the system. This file format is:
SHELL = / bin / bash
PATH = / sbin: / bin: / usr / sbin: / usr / bin
MAILTO = root / / If an error occurs, or a data output, data as e-mail sent to this account
HOME = / / / the user running the path, here is the root directory
01 * * * * root run-parts / etc / cron.hourly / / hourly / etc / cron.hourly the script
02 4 * * * root run-parts / etc / cron.daily / / daily basis / etc / cron.daily script within
22 4 * * 0 root run-parts / etc / cron.weekly / / implementation of each week / etc / cron.weekly the script
42 4 1 * * root run-parts / etc / cron.monthly / / month to execute / etc / cron.monthly the script
Attention to the "run-parts" of this argument, if this parameter is removed, then back to write a script to run the name of the folder name instead.
* * * * * Command
Time-moon week command
Column 1 for minutes 1 to 59 per minute with a * or * / 1, column 2, said that hours of 1 to 23 (0 for 0 points)
Column 3 represents the date from 1 to 31
Column 4 represents the month from 1 to 12
Identification number of the first five weeks of 0 to 6 (0 for Sunday)
Column 6 the command to run
Some examples of crontab file:
30 21 * * * / usr / local / etc / rc.d / lighttpd restart
The above example shows the 21:30 nightly restart lighttpd.
45 4 1,10,22 * * / usr / local / etc / rc.d / lighttpd restart
The above example shows the monthly 1,10,22 Day 4:45 to restart lighttpd.
10 1 * * 6,0 / usr / local / etc / rc.d / lighttpd restart
The above example shows every Saturday and Sunday 1:10 to restart lighttpd.
0,30 18-23 * * * / usr / local / etc / rc.d / lighttpd restart
The example above indicates that 18 per day: 00 to 23: 00 every 30 minutes between restart lighttpd.
0 23 * * 6 / usr / local / etc / rc.d / lighttpd restart
The above example shows every Saturday 11: 00 pm to restart lighttpd.
* * / 1 * * * / usr / local / etc / rc.d / lighttpd restart
Lighttpd restart every hour
* 23-7/1 * * * / usr / local / etc / rc.d / lighttpd restart
11 pm to 7 am, between every hour restart lighttpd
0 11 4 * mon-wed / usr / local / etc / rc.d / lighttpd restart
4 per month, Monday through Wednesday with the 11-point restart lighttpd
0 4 1 jan * / usr / local / etc / rc.d / lighttpd restart
January 1 to 4:00 lighttpd restart
AIX system log cleaning log
errclear command can be used to clean up the error log and the default error log clean-up cron on a daily basis
0 11 * * * / usr / bin / errclear-d S, O 30
0 12 * * * / usr / bin / errclear-d H 90
0 15 * * * / usr / lib / ras / dumpcheck>; / dev / null 2>; & 1
Obviously, looking for the above example, S, O type of error will be retained for 30 days, and H of the error for 90 days
delete multiple record errclear 0
errclear 7 7 days a previously deleted record
Record all error messages cron
In the / etc / syslog.conf by adding the following line
cron.err / var / cronerr.log
Cron's err definition record information to / var / cronerr.log file
IBM-AIX systems commonly used commands
Close aix command: shutdown -> shutdown, shut down all services. Halt -> is equivalent to directly turn off the power.
Restart aix: shutdown-Fr
View error message:
errpt errpt-a | more -> Page Display errpt-a> / tmp/err01 output to a file.
Clear the error message:
See the error log on AIX systems
Running in the system, some system error will be recorded in the errlog, where some errors will be displayed on the terminal. Check the error log using the following command:
# Errpt | more see all the records system
IDENTIFIER TIMESTAM PTC RESOURCE_NAME DESCRIPTION
E85C5C4C 0426104399 PS CFGLFT SOFTWARE PROGRAM ERROR
2BFA76F6 0426104099 TS SYSPROC SYSTEM SHUTDOWN BY USER
9D4CF6E7 0426104399 TO errdemon ERROR LOGGING TURNED ON
1E2AC07E 0426103999 TO errdemon ERROR LOGGING TURNED OFF
1E5EER4T 0423132999 TO clstrmgr OPERATOR NOTIFICATION
IDENTIFIER for the error number, if more information needs to be checked often used.
TIME STAMP as the time stamp, it records the wrong time, in the format: day month every year when the hours of sub-
T for the Type, it records the wrong type
P: permanent error, need attention
T: a temporary error.
C for the Class, it records the wrong type, such as
O: Errloger command messages
RESOURCE_NAME the error sources
DESCRIPTION description of the error
# Errpt-aj <IDENTIFIER> View detailed record of the contents of the system
IDENTIFIER which is the error number, such as # errpt-aj 0426104399
# Errpt-dH view the system records all of the hardware error
# AIX regularly monitor the disk space problem of the alarm and system error log
00 02 * * * / var / snlog / dislog
00 16 * * * / var / snlog / dislog
#! / Usr / bin / ksh
/ Var / snlog / disfs> / var / snlog / errlog `hostname`
errpt>> / var / snlog / errlog `hostname`
lsps-a>> / var / snlog / errlog `hostname`
echo "==` hostname `=="
df | head -1; df | grep 100%; df | grep 99%; df | grep 98%; df | grep 97%; df | grep 96%;
printf "################################################ ########################## \ n "
== P6550b2 ==
Filesystem 512-blocks Free% Used Iused% Iused Mounted on
/ Dev/fslv00 100663296 4015848 97% 8125 2% / db2data
IDENTIFIER TIMESTAMP TC RESOURCE_NAME DESCRIPTION
F7FA22C9 0917162810 IO SYSJ2 UNABLE TO ALLOCATE SPACE IN FILE SYSTEM
38A8D4BB 0825181810 IH ent0 HEA PORT DOWN
38A8D4BB 0811172110 IH ent0 HEA PORT DOWN
38A8D4BB 0713171610 IH ent0 HEA PORT DOWN
38A8D4BB 0713165310 IH ent0 HEA PORT DOWN
38A8D4BB 0713162710 IH ent0 HEA PORT DOWN
Page Space Physical Volume Volume Group Size% Used Active Auto Type
paging00 hdisk2 rootvg 3072MB 10 yes yes lv
hd6 hdisk3 rootvg 3072MB 10 yes yes lv
p6550b2/var/snlog # lsps-a
Rolls of paging space physics group size% of the automatic type of use activities
paging00 hdisk2 rootvg 3072MB 11 yes yes lv
hd6 hdisk3 rootvg 3072MB 11 yes yes lv
Linux / Unix time is set automatically restart the application (in resin as an example)
1. First of all, the resin will not take the initiative to restart automatically load Java environment variables
So need to edit the resin / bin directory httpd.sh, configure its independent operating environment.
# Vi httpd.sh (Note: the first line into the below)
export JAVA_HOME =......
export CLASSPATH =......
export PATH =......
2. Then, edit the crontab, configure the timer.
# Crontab-e (following injection)
0 1 * * * / usr / local / resin / bin / httpd.sh restart
(1 am every day automatically restart)
(Note that the configuration of the time in which to # clock - show show time as a reference)
3. Saved, check the configuration contents
4. Restart / etc / init.d / directory crond, the configuration to take effect
# Crond stop
# Crond start
# Crond restart
5. See cron log
# Ls / var / log / cron * (view the log file)
# Cat / var / log / cron (see details)
Detailed and examples on the crontab's, please refer to: