CentOS crontab regular tasks

A: Check CRONTAB Service 

1. Check CRONTAB tool has been installed on the host 

crontab -l 


2. Check that the service has been launched CRONTAB 

Status crond Service - in fact, this command can also check for other services, such as service httpd status detection apache is running


3. Install

yum install vixie-cron
yum install crontabs

vixie-cron cron package is a main routine;
crontabs package is used to install, uninstall, or include a program for driving the table of the cron daemon.

4. Start Services

/ Sbin / Service crond Start - start service 
/ sbin / Service crond STOP - Close Services 
/ sbin / Service crond restart - restart the service 
/ sbin / Service crond reload - reload the configuration

 

II: Command Function 

By crontab command, we can execute the specified system command or shell script script at fixed intervals. Unit time interval can be minutes, hours, days, months, weeks and any combination of the above. This command is very close set of log periodic analysis of data backup or work.

 

1. -u user: to set a user's crontab service, for example, "- u ixdba" represents a set ixdba user's crontab service, this parameter generally have root user to run.

  1. file: file is the file name of the command, said it would file as a crontab task list file and loaded into crontab. If you do not specify the file on the command line, crontab command will accept commands entered on standard input (keyboard), and load them crontab.

  2. -e: crontab edit the contents of a user's files. If you do not specify a user, then edit the current user's crontab file. (Common)

  3. -l: Displays the contents of a user's crontab file, if you do not specify a user, then displays the current contents of the user's crontab file. (Common)

  4. -r: delete a user's crontab file from / var / spool / cron directory, if you do not specify a user, the default is to delete the current user's crontab file.

  5. -i: When you delete a user's crontab file to the confirmation prompt.

Here are the two most commonly used commands: 
crontab the -l view the current list of tasks, in fact, it is the content of crontab file 
crontab -e to open the regular tasks list file for editing

crontab - U - set a user's cron service, usually root user needs at this time to execute the command parameter 
crontab - L - set out in detail the contents of a user cron services     
crontab - r - delete a user did not the service cron     
crontab - E - edit a user's cron service

 

Four: crontab file description 


crontab file created by the user, each row represents a task, each field representing each row of a setting, its format is divided into six fields, set the time period is the period of the first five, the sixth paragraph is command section to be executed in the following format:

minute hour day month week command

among them:

  1. minute : min expressed, may be any integer from 0 to 59.
  2. hour : the hour, may be any integer from 0 to 23.
  3. Day : the date, can be any integer from 1 to 31.
  4. month The : the month, can be any integer from 1-12.
  5. Week : represents the day of the week, it can be any integer from 0 to 7, where 0 or 7 represents Sunday.
  6. the Command : command to be executed, the system can command, you can also write their own script files.

In fact, using a map can better understand 
Write pictures described here

Five: Common examples 


Example 1: every 1 minute to perform a command 
commands: 
* * * * * command

Example 2: 3 hour and 15 minutes execute 
command: 
3,15 * * * * Command

Example 3: In the first 15 minutes and 3 perform 8:00 to 11:00 of 
the command: 
3,15 Command 8-11 * * *

Example 4: every day 8:00 to 11:00 of the first 15 minutes and 3 execute 
the command: 
3,15 8-11 * / 2 * * Command

Example 5: Each of the first 15 minutes and 3 perform Monday 8:00 to 11:00 of 
the command: 
3,15. 1 Command 8-11 * *

Example 6: night 21:30 smb restart 
command: 
30 * * * 21 is the restart /etc/init.d/smb

Example 7: 1 month, 10, 22 of 4:45 smb restart 
command: 
45. 4 1,10,22 * * the restart /etc/init.d/smb

Example 8: every Saturday and Sunday 1:10 to restart the smb 
command: 
10 * 1 * 6,0 /etc/init.d/smb restart

Example 9:18 per day: 00-23: every 30 minutes between 00 smb restart 
command: 
0,30 18-23 * * * the restart /etc/init.d/smb

Example 10: Every Saturday night, 11: 00 pm to restart the smb 
command: 
0 23 * 6 * /etc/init.d/smb restart

Example 11: smb per hour restart 
command: 
* * / * * * /etc/init.d/smb the restart. 1

Example 12: between 11 pm to 7 am, every hour smb restart 
command: 
* 23-7 / /etc/init.d/smb the restart. 1 * * *

Example 13: Monthly No. 4 and 11:00 from Monday to Wednesday to restart the smb 
command: 
0 11 4 * Mon-Wed /etc/init.d/smb restart

Example 14: 1 January of 4:00 smb restart 
command:  
0 4 1 jan * /etc/init.d/smb restart

Example 15: script executed every 30 seconds directories within /etc/cron.hourly 
commands: 
* / * * * * the root. 1 RUN-Parts /etc/cron.hourly 
* / * * * *. 1 SLEEP 30s; the root-RUN Parts /etc/cron.hourly

Guess you like

Origin www.cnblogs.com/VicLiu/p/12156477.html