CronTab任務周期計劃

來源:互聯網
上載者:User

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} 拒絕和允許使用者使用crontab Vixie-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 crondroot     20641  0.0  0.6 139684  1468 pts/1    S+   17:30   0:00 crontab -ezwhset   20642  0.0  0.7 119284  1756 pts/1    S+   17:30   0:00 /bin/vi /tmp/crontab.YphQpHroot     20663  0.0  0.3 103236   856 pts/0    S+   17:31   0:00 grep cron[root@nagios ~]# lsof -c crontabCOMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF   NODE NAMEcrontab 20641 root  cwd    DIR              253,0     4096 130818 /rootcrontab 20641 root  rtd    DIR              253,0     4096      2 /crontab 20641 root  txt    REG              253,0    47520 401259 /usr/bin/crontabcrontab 20641 root  mem    REG              253,0     5952 261889 /lib64/security/pam_deny.socrontab 20641 root  mem    REG              253,0    18592 261891 /lib64/security/pam_env.socrontab 20641 root  mem    REG              253,0    18592 261903 /lib64/security/pam_limits.socrontab 20641 root  mem    REG              253,0    10224 261901 /lib64/security/pam_keyinit.socrontab 20641 root  mem    REG              253,0    10240 261906 /lib64/security/pam_loginuid.socrontab 20641 root  mem    REG              253,0     6040 261912 /lib64/security/pam_permit.socrontab 20641 root  mem    REG              253,0    14384 261923 /lib64/security/pam_succeed_if.socrontab 20641 root  mem    REG              253,0    10200 261905 /lib64/security/pam_localuser.socrontab 20641 root  mem    REG              253,0    51952 261929 /lib64/security/pam_unix.socrontab 20641 root  mem    REG              253,0   113432 261657 /lib64/libnsl-2.12.socrontab 20641 root  mem    REG              253,0    14456 261884 /lib64/security/pam_access.socrontab 20641 root  mem    REG              253,0    65928 261663 /lib64/libnss_files-2.12.socrontab 20641 root  mem    REG              253,0 99158576 397021 /usr/lib/locale/locale-archivecrontab 20641 root  mem    REG              253,0   383504 261640 /lib64/libfreebl3.socrontab 20641 root  mem    REG              253,0    40400 261651 /lib64/libcrypt-2.12.socrontab 20641 root  mem    REG              253,0  1916568 261647 /lib64/libc-2.12.socrontab 20641 root  mem    REG              253,0   113096 261709 /lib64/libaudit.so.1.0.0crontab 20641 root  mem    REG              253,0    19536 261653 /lib64/libdl-2.12.socrontab 20641 root  mem    REG              253,0    55848 261879 /lib64/libpam.so.0.82.2crontab 20641 root  mem    REG              253,0   122040 261718 /lib64/libselinux.so.1crontab 20641 root  mem    REG              253,0   154464 261636 /lib64/ld-2.12.socrontab 20641 root    0u   CHR              136,1      0t0      4 /dev/pts/1crontab 20641 root    1u   CHR              136,1      0t0      4 /dev/pts/1crontab 20641 root    2u   CHR              136,1      0t0      4 /dev/pts/1crontab 20641 root    3u  unix 0xffff88000225c380      0t0  91831 socketcrontab 20641 root    5u   REG              253,0       68 916745 /tmp/crontab.YphQpH 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.