Linux配置定時,使用 crontab,linux配置crontab
Linux配置定時任務,大家都知道使用crontab這個系統功能,但有時候我們需要區分使用者執行,下面就直接說一下2種方法的區別:
方法1:
使用命令 crontab -e 然後直接編輯定時指令碼。
這樣執行以後,屬於使用者自訂的,會被寫到 /var/spool/cron 目錄下,產生一個和使用者名稱一致的檔案,檔案內容就是我們編輯的定時指令碼。
如:
[root@localhost cron.d]# cd /var/spool/cron[root@localhost cron]# ll總用量 4-rw-------. 1 root root 52 12月 9 10:58 root[root@localhost cron]# pwd/var/spool/cron[root@localhost cron]# cat root 30 03 * * * /root/automysqlbackup.sh
方法2:
使用命令 vi /etc/crontab 編輯定時指令碼。
如:
[root@localhost ~]# 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 root@192.168.231.35::resource /hyy/bak/resource 30 4 * * * root /usr/bin/rsync -vzrtopg --progress --delete root@192.168.231.35::log /hyy/bak/log############################################[root@localhost ~]#
(系統級的)做系統級配置我們會直接配置 /etc/crontab
(使用者級的)一般還是建議大家使用 crontab -e ,這樣系統也會幫著檢查我們配置的指令碼文法。