Linux配置定時,使用 crontab -e 與 直接編輯 /etc/crontab 的區別

 

Linux配置定時任務,你們都知道使用crontab這個系統功能,但有時候咱們須要區分用戶執行,下面就直接說一下2種方法的區別:linux

方法1:sql

使用命令 crontab -e 而後直接編輯定時腳本。bash

這樣執行之後,屬於用戶自定義的,會被寫到 /var/spool/cron 目錄下,生成一個和用戶名一致的文件,文件內容就是咱們編輯的定時腳本。oop

如:post

[html]  view plain copy
  1. [root@localhost cron.d]# cd /var/spool/cron  
  2. [root@localhost cron]# ll  
  3. 總用量 4  
  4. -rw-------. 1 root root 52 12月  9 10:58 root  
  5. [root@localhost cron]# pwd  
  6. /var/spool/cron  
  7. [root@localhost cron]# cat root   
  8. 30 03 * * * /root/automysqlbackup.sh  

方法2:url

使用命令 vi /etc/crontab 編輯定時腳本。spa

如:.net

[html]  view plain copy
  1. [root@localhost ~]# cat /etc/crontab                                                                                                                                                                        
  2. SHELL=/bin/bash                                                                                                                                                                                             
  3. PATH=/sbin:/bin:/usr/sbin:/usr/bin                                                                                                                                                                          
  4. MAILTO=root                                                                                                                                                                                                 
  5. HOME=/                                                                                                                                                                                                      
  6.                                                                                                                                                                                                             
  7. # run-parts                                                                                                                                                                                                 
  8. 30 * * * * root /usr/sbin/ntpdate 210.72.145.44                                                                                                                                                             
  9. #30 8 * * * root /usr/sbin/ntpdate 132.228.90.101                                                                                                                                                           
  10. 01 * * * * root run-parts /etc/cron.hourly                                                                                                                                                                  
  11. 02 4 * * * root run-parts /etc/cron.daily                                                                                                                                                                   
  12. 22 4 * * 0 root run-parts /etc/cron.weekly                                                                                                                                                                  
  13. 42 4 1 * * root run-parts /etc/cron.monthly                                                                                                                                                                 
  14. */1 * * * * root run-parts /opt/openoffice.org3/program/start.sh                                                                                                                                            
  15. ############################################                                                                                                                                                                
  16.                                                                                                                                                                                                             
  17. 30 4 * * * root /usr/bin/rsync -vzrtopg --progress --delete root@192.168.231.35::resource /hyy/bak/resource   
  18. 30 4 * * * root /usr/bin/rsync -vzrtopg --progress --delete root@192.168.231.35::log /hyy/bak/log  
  19. ############################################  
  20. [root@localhost ~]#   

 

(系統級的)作系統級配置咱們會直接配置 /etc/crontab

(用戶級的)通常仍是建議你們使用 crontab -e ,這樣系統也會幫着檢查咱們配置的腳本語法。

相關文章
相關標籤/搜索