linux command script timed run crontab

 

Brief introduction

Linux, the duty cycle is generally performed by the cron daemon to handle ps -ef | grep cron 

cron read one or more configuration files, the configuration file contains the command line and call time.

cron configuration file is called "crontab", it is a "cron table" shorthand.

 

1, / var / spool / cron / This directory is stored for each user (including root) of the crontab task, the name of each person's name to create a task, such as the user's crontab task hdfs build the corresponding file is / var / spool / cron / hdfs

[root@el-hadoop-1 cron]# ll
total 4
-rw------- 1 hdfs hdfs 2185 Dec 31 17:11 hdfs
[root@el-hadoop-1 cron]# pwd
/var/spool/cron

 

Usually a user crontab most one file (such as: root, hdfs, etc.), 
which corresponds to the log / var / spool / mail / (or / var / spool / mail / hdfs ) file, in fact it is not inside the folder it will record logs, our only specified directory.

 

/ Etc / crontab This file is responsible for arranging developed by system administrators maintain the system crontab and other tasks.

[root@el-hadoop-1 spool]# vim  /etc/crontab 

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *   *   *   *

 

cron service

  cron is a linux under the regular implementation of the tool, you can run the job without the need for manual intervention.
  / sbin / Service crond Start     // start the service 
  / sbin / Service crond STOP      // close the service 
  / sbin / Service crond restart   // restart the service 
  / sbin / Service crond reload    // reload the configuration 
  / sbin / Service crond Status    // check the service status 

 

crontab usage 

crontab command is used to install, remove or list the tables used to drive the cron daemon, a command sequence to the user needs to perform to get into crontab file execution.
Each user can have their own crontab file, / var / spool / crontab file directly under the cron can not create or modify direct the crontab command file is created with the crontab -e

How to enter a command and the time required to perform in the crontab file, the file in each line consists of six domains, of which the first five fields is the time specified command is executed, the last field is the command to be executed.

" / " Representing each of meaning, " / 5 " means every 5 unit, " - " represents the numbers from one to a certain number, " , " separate from a few discrete numbers.
- L crontab current display on the standard output. 
- r Remove the current crontab file. 
-e editor Use VISUAL or EDITOR environment variables referred to edit the current crontab file.

 

 

such as:

10  6 * * * echo  " . The Hello Good Morning World " > /tmp/test.txt # every morning 6:10, echo output to /tmp/test.txt this file inside, which log records; 
> is covered , >> is added in the form of written; * / 1 * * * * echo " . Have a BREAK now " >> / tmp / test.txt # executed once per minute; 0 * / 2 * * * echo " A BREAK now Have. " >> /tmp/test.txt # 2h execute every time;

10 1 * * * /home/hopson/apps/acitve_analysis.sh &>> /tmp/logs/acitve_analysis.log

Guess you like

Origin www.cnblogs.com/shengyang17/p/12131985.html