Crontab timer (including shell execution) Today I saw this good tutorial on the Internet, which is about CronTab and clearly written. So I will repost it and share it with you. The following files are restricted for users to use crontab:/etc/cron. allow/etc/cron. deny. After a Job Schedule is created using crontab, it is recorded in/var/spool/cron. Each task executed by cron is recorded in/varlog/cron. Crontab parameter: www.2cto.com-u: only root can be used to help other users create or remove work schedules. -L: view the work content of crontab
-R: removes all crontab work content, removes one item, and uses-e to edit it. Example 1: Send a mail to the root account at every day. [Root @ lyy etc] # crontab-e # Use vi to edit 0 12 *** mail root-s "at" </root /. bashrc has six fields for each job: minute Hour Date month week instruction 0-59 0-23 1-31 1-12 0-7 INSTRUCTION #0 and 7 both represent Sunday auxiliary special characters: * (asterisk) represents any time, (comma) represents the separation time. For example, and represent 3-6 (minus signs) within a period of time. For example, from to, it means 3-6/n (diagonal line) n represents a number, that is, every n units. Such as every five minutes,/5 Example 2: output characters on the screen every three minutes
[Root @ lyy etc] # crontab-e [root @ lyy etc] # crontab-l */3 ***** echo "hello world !!!!! ">/Dev/pts/0 # pts/0: Use the telnet Terminal interface to view the record www.2cto.com [root @ lyy etc] # cat/var/log/cronDec 12 20:27:01 lyy crond [9865]: (root) CMD (echo "hello world !!!!! "& Gt;/dev/pts/0) Dec 12 20:30:01 lyy crond [9908]: (root) CMD (echo" hello world !!!!! "& Gt;/dev/pts/0) Example 3: send an email to pc [root @ lyy etc] # crontab-e 30 14*3 mail pc-s "test" & lt; /home/text.txt crontab-e is designed for your cron. If it is a system routine task, you only need to compile the/etc/crontab file.
View/etc/crontab content [root @ lyy etc] # cat/etc/crontab SHELL =/bin/bash # interface PATH =/sbin:/bin:/usr/sbin: /usr/bin # search MAILTO = root # HOME with mail sender =/# HOME Directory # run-parts 01 ***** root run-parts/etc/cron. hourly #02 4 *** root run-parts/etc/cron every hour. daily # daily 22 4 ** 0 root run-parts/etc/cron. weekly # Every Sunday 42 4 1 ** root run-parts/etc/cron. monthly # cancel unwanted output items on the first day of each month: redirect the output results to the/dev/null security check using commands: because some Trojans are added to So you can check/var/log/cron to find out. The Week and the day and month cannot coexist at the same time, for example, www.2cto.com 30 12 12 11 9 5 root echo "just test" # This is an incorrect syntax. It was originally thought that the task was executed on Friday, but the system may determine that the task is executed once every Friday or on July 15, every year. The job anacronanacron during the wake-up period cannot replace crontab, which is used to process crontab execution in a non-24-hour online linux system. It is executed on a daily basis or after being started. It checks and runs crontab during the shutdown period, and then stops automatically. Linux Command: create task crontab-e */1 ***** echo 'ddd '/var/test.txt every minute write export dddto test.txt file *****/1 * sh/var/jboss-4.0.5.GA/server/default/ log/temp/delete_log1.sh run delete_log1.sh script sh once a month (delete_log1.sh) dd = 'date-d "1 month ago" + % y-% m' rm-vf/var/temp/log.20 $ dd-* Delete matching for one month from the current time file author zreodown