標籤:blog ar os 使用 sp on 檔案 2014 art
Linux配置定時任務,大家都知道使用crontab這個系統功能,但有時候我們需要區分使用者執行,下面就直接說一下2種方法的區別:
方法1:
使用命令 crontab -e 然後直接編輯定時指令碼。
這樣執行以後,屬於使用者自訂的,會被寫到 /var/spool/cron 目錄下,產生一個和使用者名稱一致的檔案,檔案內容就是我們編輯的定時指令碼。
如:
[[email protected] cron.d]# cd /var/spool/cron[[email protected] cron]# ll總用量 4-rw-------. 1 root root 52 12月 9 10:58 root[[email protected] cron]# pwd/var/spool/cron[[email protected] cron]# cat root 30 03 * * * /root/automysqlbackup.sh
方法2:
使用命令 vi /etc/crontab 編輯定時指令碼。
如:
[[email protected] ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # run-parts 30 * * * * root /usr/sbin/ntpdate 210.72.145.44 #30 8 * * * root /usr/sbin/ntpdate 132.228.90.101 01 * * * * root run-parts /etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly */1 * * * * root run-parts /opt/openoffice.org3/program/start.sh ############################################ 30 4 * * * root /usr/bin/rsync -vzrtopg --progress --delete [email protected]::resource /hyy/bak/resource 30 4 * * * root /usr/bin/rsync -vzrtopg --progress --delete [email protected]::log /hyy/bak/log############################################[[email protected] ~]#
(系統級的)做系統級配置我們會直接配置 /etc/crontab
(使用者級的)一般還是建議大家使用 crontab -e ,這樣系統也會幫著檢查我們配置的指令碼文法。
Linux配置定時,使用 crontab -e 與 直接編輯 /etc/crontab 的區別