CronTab 任务周期计划
格式:* * * * * command分(0-59)、时(0-23)、日(1-31)、月(1-12)、周(0-6)说明:1、星号可以匹配所有字符2、一个整数、必须精确匹配3、用短划线隔开的两个整数,它们匹配的是值的范围。4、时间范围后加斜扛和一个步长值。1-10/2普通用户流程:crontab -e crontab是设置了setuid的,所以用户具有他的权限也就是root,并会在/tmp/cron....文件处理后保存在/var/spool/cron/$username中。日志:/var/log/cron配置目录:/var/run/crond.pid 进程号地址/etc/crontab 使用指导文件/etc/$weekday. 等分别时日月周的目录,即可以把脚本放进去他会按时执行。/etc/cron.{deny,allow} 拒绝和允许用户使用crontabVixie-Cron:centos安装时会默认安装此包,此包可以包括一个步长值。也就是如1,3,6,9,12 可以写成,1-12/3 除以3。所谓的*/1 */2也就是每一分钟每两分钟运行command。即1-59/{2,3}。%号的运用:%百分号表示command中的换行,只有第一个百分号之前的文本才包含在实际命令中,其余的行则作为该命令的标准输入。安装:yum install -y crontabs使用:crontab --helpcrontab -e #检出一个crontab副本,调用vi编辑它,并重新保存在crontab目录。crontab -l #将crontab的内容打印到标准输出。crontab -r #册除并不留任何内容。......root册除其它用户。crontab -r $username[root@nagios ~]# crontab --helpcrontab: invalid option -- '-'crontab: usage error: unrecognized optionusage:crontab [-u user] filecrontab [-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 crondrwxr-xr-x 2 root root 4096 Apr 2 00:59 cron.ddrwxr-xr-x. 2 root root 4096 Sep 27 2011 cron.daily-rw-r--r-- 1 root root 0 Jul 19 2011 cron.denydrwxr-xr-x 2 root root 4096 Sep 27 2011 cron.hourlydrwxr-xr-x 2 root root 4096 Sep 27 2011 cron.monthly-rw-r--r-- 1 root root 457 Sep 27 2011 crontabdrwxr-xr-x 2 root root 4096 Sep 27 2011 cron.weekly[root@nagios ~]# cat /etc/crontab SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootHOME=/# 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 cronroot 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