1,630 瀏覽數

Ubuntu 自動化工作排程管理

一般的自動化排程請參考 http://benjr.tw/421

自從把系統換成 Ubuntu 發現自動執行程式沒有在固定時間內執行.所以有些習慣要修改一下.

像是在 /etc/cron.hourly/, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly 有些規則.

The files in /etc/cron.daily are run by the run-parts(8) command and it’s default is to ignore programs that don’t match various rules.

run-parts runs all the executable files named within constraints described below, found in directory directory. Other files and directories are silently ignored.

If neither the –lsbsysinit option nor the –regex option is given then the names must consist entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens.

簡單來說只能用 ASCII upper-case letters (大寫) 以及 lower-case letters(小寫), ASCII digits(數字), ASCII underscores(下劃線), and ASCII minus-hyphens(減去連字符). 像是 “." 也不能用,以前習慣寫 script 時用 .sh 當結尾也不行.

自動執行的區域可以用 run-parts 測試一下.

root@Benjr:~# run-parts --test /etc/cron.daily/
/etc/cron.daily//apache2
/etc/cron.daily//apport
/etc/cron.daily//apt
/etc/cron.daily//aptitude
/etc/cron.daily//bsdmainutils
/etc/cron.daily//dpkg
/etc/cron.daily//logrotate
/etc/cron.daily//man-db
/etc/cron.daily//mlocate
/etc/cron.daily//passwd
/etc/cron.daily//popularity-contest
/etc/cron.daily//standard
/etc/cron.daily//update-notifier-common

奇怪我寫的程式 benjr.backup.sh 怎麼沒有執行呢!!檔案明明在的阿!!

root@Benjr:/etc/cron.daily# ll
total 88
drwxr-xr-x  2 root root  4096 Sep 24 12:02 ./
drwxr-xr-x 91 root root  4096 Sep 18 17:51 ../
-rwxr-xr-x  1 root root   633 Jul 12 21:37 apache2*
-rwxr-xr-x  1 root root   219 Apr 10  2012 apport*
-rwxr-xr-x  1 root root 15399 Dec 12  2012 apt*
-rwxr-xr-x  1 root root   314 Oct  5  2012 aptitude*
-rwxr-xr-x  1 root root   311 Sep 17 19:35 benjr.backup.sh*
-rwxr-xr-x  1 root root   502 Mar 31  2012 bsdmainutils*
-rwxr-xr-x  1 root root   256 Jan  8  2013 dpkg*
-rwxr-xr-x  1 root root   372 Oct  5  2011 logrotate*
-rwxr-xr-x  1 root root  1365 Dec 29  2012 man-db*
-rwxr-xr-x  1 root root   606 Aug 17  2011 mlocate*
-rwxr-xr-x  1 root root   249 Sep 13  2012 passwd*
-rw-r--r--  1 root root   102 Jun 20  2012 .placeholder
-rwxr-xr-x  1 root root  2417 Jul  2  2011 popularity-contest*
-rwxr-xr-x  1 root root  2947 Jun 20  2012 standard*
-rwxr-xr-x  1 root root   214 Sep 11  2012 update-notifier-common*

把檔名修改一下 benjr.backup.sh -> benjr-backup 就可以使用了

root@Benjr:/etc/cron.daily# mv benjr.backup.sh benjr-backup

root@Benjr:/etc/cron.daily# run-parts --test /etc/cron.daily/
/etc/cron.daily//apache2
/etc/cron.daily//apport
/etc/cron.daily//apt
/etc/cron.daily//aptitude
/etc/cron.daily//bsdmainutils
/etc/cron.daily//benjr-backup
/etc/cron.daily//dpkg
/etc/cron.daily//logrotate
/etc/cron.daily//man-db
/etc/cron.daily//mlocate
/etc/cron.daily//passwd
/etc/cron.daily//popularity-contest
/etc/cron.daily//standard
/etc/cron.daily//update-notifier-common

發表迴響