1. Definition:
The crontab command is commonly used in Unix-and Unix-like operating systems to set instructions that are executed periodically. The command reads the instruction from the standard input device and stores it in a "crontab" file for later reading and execution. The word derives from the Greek language Chronos (χρνο), which was originally meant to be time. Often, crontab stored instructions are activated by the daemon, Crond often run in the background, and every minute checks whether a scheduled job needs to be performed. This type of work is generally called cron jobs.
2, installation (default comes with crontab)
If you execute the crontab report the following error is required to install.
-bash:crontab:command not found
1). Confirm that the crontab is installed:
Execute the crontab command if you do not found, it indicates that there is no installation
2). Install Crontab
Execute Yum install-y Vixie-cron
3). Confirm that the installation is successful:
Executive Crontab-l
4). See if the boot is set to start automatically
Chkconfig--list Crond
5). Start crontab
Service Crond Start
3. Syntax usage
Use Permissions:
Root UserAnd
owner of the crontab file
Grammar: crontab [-E [Username]|-l [Username]|-r [username]|-v] [username]| File]
Description: Crontab is used to allow a user to execute a program at a fixed time or at a fixed interval, in other words, a user-like time schedule. -u user refers to the setting of the time table for the specified user, which presupposes that you must have permission (for example, root) to specify another's time schedule. If you do not use the-u user, it means setting your own schedule.
Parameters:
- e[UserName]:
Execute the text editor to set the time table, the default text editor is VI, if you want to use a different text editor, set the visual environment variable to specify the text editor (for example, setenv visual Joe)
-R [UserName]: Delete current Schedule table
-L [UserName]: Lists the current schedule table
-V [UserName]: Lists the status of the user cron job
Eg: view the current user's schedule table
Crontab-l
4. Transcription shell (. sh) script
Here are a few examples of uploading and downloading via FTP, the difference betweenmget and get is the difference between multiple files and a file, mget can get multiple files, get can only get one, put and mput.
1). FTP automatically logs in bulk download files.
# # # # # # #从ftp服务器上的/home/data to the local/home/databackup####
# !/bin/bashftp-n<<! 192.168.1.171123456/home//home/*closebye!
2). FTP automatically log in to upload files.
# # # #本地的/home/data#### on/home/databackup to FTP server # !/bin/bashftp-n<<192.168.1.171123456/home//home/* closebye!
3). FTP automatic login to download individual files.
# # # #ftp服务器上下载/home/data/a.sh to local/home/databackup#### # !/bin/bashftp-n<<192.168.1.171123456/home//home/ Databackuppromptget a.sh a.shclosebye!
4). FTP Automatic login uploads a single file.
# # # #把本地/home/databachup/a.sh up Ftp/home/databackup down # # # # !/bin/bashftp-n<<192.168.1.171123456/home//home/ Databackuppromptput a.sh a.shclosebye!
PS: above shell each field meaning can view http://www.cnblogs.com/0201zcr/p/4737508.html
4. Put the shell script in crontab and run it regularly
the format of the schedule table is as follows: F1 F2 F3 f4 F5 program where F1 is expressed in minutes, F2 represents hours, F3 represents the day of the month, F4 represents the month, and F5 represents the day of the one week. Program represents the programs to execute.
By executing the following statement, you can go to the vi-like text editor interface, which allows us to invoke a script periodically by transcribing the above-mentioned schedule table.
Crontab-e
Eg: Execute a script every 5 minutes
The first one is */5, this kind of writing system will not support */5 * * * * */xxx/task.sh The second method is more cumbersome, but all systems support: 0, 5,10,15,20,25,30,35,40,45,50,55 * * * */xx/task.sh
list crontab FilesIn order to list the crontab file, you can use: $crontab-L
Edit crontab fileIf you want to add, delete, or edit entries in the Crontab file, and the editor environment variable is set to VI, then you can use VI to edit the crontab file, the corresponding command is: $ crontab-e You can modify the Crontab file and exit as you would edit any other file using VI.
Delete crontab fileIn order to delete the crontab file, you can use: $ crontab-r
Note crontab fileIf you do not want to delete the written crontab file, add it before the crontab file
#Comment out the file.
Thanks: Thank you for your patience and reading!
Linux shell crontab (timed task) detailed