CronTab 任务周期计划
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、雅安服务器托管、营销软件、网站建设、台州网站维护、网站推广。
* * * * * command
分(0-59)、时(0-23)、日(1-31)、月(1-12)、周(0-6) |
1、星号可以匹配所有字符
2、一个整数、必须精确匹配 3、用短划线隔开的两个整数,它们匹配的是值的范围。 4、时间范围后加斜扛和一个步长值。1-10/2 |
crontab --help
crontab -e #检出一个crontab副本,调用vi编辑它,并重新保存在crontab目录。 crontab -l #将crontab的内容打印到标准输出。 crontab -r #册除并不留任何内容。 |
[root@nagios ~]# crontab --help
crontab: invalid option -- '-' crontab: usage error: unrecognized option usage:crontab [-u user] file crontab [-u user] [ -e | -l | -r ] (default operation is replace, per 1003.2) -e(edit user's crontab) -l(list user's crontab) -r(delete user's crontab) -i(prompt before deleting user's crontab) -s(selinux context) [root@nagios ~]# ll /usr/bin/crontab -rwsr-xr-x 1 root root 47520 Jul 19 2011 /usr/bin/crontab [root@nagios ~]# cat /var/run/crond.pid 2074 [root@nagios ~]# ll /etc/ |grep -E cron drwxr-xr-x 2 root root 4096 Apr 2 00:59 cron.d drwxr-xr-x. 2 root root 4096 Sep 27 2011 cron.daily -rw-r--r-- 1 root root 0 Jul 19 2011 cron.deny drwxr-xr-x 2 root root 4096 Sep 27 2011 cron.hourly drwxr-xr-x 2 root root 4096 Sep 27 2011 cron.monthly -rw-r--r-- 1 root root 457 Sep 27 2011 crontab drwxr-xr-x 2 root root 4096 Sep 27 2011 cron.weekly [root@nagios ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # 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 # | | | | | # * * * * * user-name command to be executed [root@nagios ~]# ll /var/spool/cron/ total 8 -rw------- 1 root root 60 Apr 2 01:33 root -rw------- 1 zwhset zwhset 68 Apr 2 01:51 zwhset [root@nagios ~]# tail -5 /var/log/cron Apr 2 17:24:01 nagios CROND[20544]: (root) CMD (/bin/sh ~/hello) Apr 2 17:25:01 nagios CROND[20549]: (root) CMD (/bin/sh ~/hello) Apr 2 17:25:01 nagios CROND[20550]: (root) CMD (/bin/sh ~/hello) Apr 2 17:25:01 nagios CROND[20551]: (zwhset) CMD (echo "hello" >> ~/1.txt) Apr 2 17:25:01 nagios CROND[20552]: (zwhset) CMD (echo "hello" >> ~/1.txt) |
[root@nagios ~]# ps aux |grep cron
root 2074 0.0 0.5 117212 1316 ? Ss 01:40 0:04 crond root 20641 0.0 0.6 139684 1468 pts/1 S+ 17:30 0:00 crontab -e zwhset 20642 0.0 0.7 119284 1756 pts/1 S+ 17:30 0:00 /bin/vi /tmp/crontab.YphQpH root 20663 0.0 0.3 103236 856 pts/0 S+ 17:31 0:00 grep cron [root@nagios ~]# lsof -c crontab COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME crontab 20641 root cwd DIR 253,0 4096 130818 /root crontab 20641 root rtd DIR 253,0 4096 2 / crontab 20641 root txt REG 253,0 47520 401259 /usr/bin/crontab crontab 20641 root mem REG 253,0 5952 261889 /lib64/security/pam_deny.so crontab 20641 root mem REG 253,0 18592 261891 /lib64/security/pam_env.so crontab 20641 root mem REG 253,0 18592 261903 /lib64/security/pam_limits.so crontab 20641 root mem REG 253,0 10224 261901 /lib64/security/pam_keyinit.so crontab 20641 root mem REG 253,0 10240 261906 /lib64/security/pam_loginuid.so crontab 20641 root mem REG 253,0 6040 261912 /lib64/security/pam_permit.so crontab 20641 root mem REG 253,0 14384 261923 /lib64/security/pam_succeed_if.so crontab 20641 root mem REG 253,0 10200 261905 /lib64/security/pam_localuser.so crontab 20641 root mem REG 253,0 51952 261929 /lib64/security/pam_unix.so crontab 20641 root mem REG 253,0 113432 261657 /lib64/libnsl-2.12.so crontab 20641 root mem REG 253,0 14456 261884 /lib64/security/pam_access.so crontab 20641 root mem REG 253,0 65928 261663 /lib64/libnss_files-2.12.so crontab 20641 root mem REG 253,0 99158576 397021 /usr/lib/locale/locale-archive crontab 20641 root mem REG 253,0 383504 261640 /lib64/libfreebl3.so crontab 20641 root mem REG 253,0 40400 261651 /lib64/libcrypt-2.12.so crontab 20641 root mem REG 253,0 1916568 261647 /lib64/libc-2.12.so crontab 20641 root mem REG 253,0 113096 261709 /lib64/libaudit.so.1.0.0 crontab 20641 root mem REG 253,0 19536 261653 /lib64/libdl-2.12.so crontab 20641 root mem REG 253,0 55848 261879 /lib64/libpam.so.0.82.2 crontab 20641 root mem REG 253,0 122040 261718 /lib64/libselinux.so.1 crontab 20641 root mem REG 253,0 154464 261636 /lib64/ld-2.12.so crontab 20641 root 0u CHR 136,1 0t0 4 /dev/pts/1 crontab 20641 root 1u CHR 136,1 0t0 4 /dev/pts/1 crontab 20641 root 2u CHR 136,1 0t0 4 /dev/pts/1 crontab 20641 root 3u unix 0xffff88000225c380 0t0 91831 socket crontab 20641 root 5u REG 253,0 68 916745 /tmp/crontab.YphQpH |