Linux配置定时,使用 crontab -e 与 直接编辑 /etc/crontab 的区别

 

Linux配置定时任务,大家都知道使用crontab这个系统功能,但有时候我们需要区分用户执行,下面就直接说一下2种方法的区别:

方法1:

使用命令 crontab -e 然后直接编辑定时脚本。

这样执行以后,属于用户自定义的,会被写到 /var/spool/cron 目录下,生成一个和用户名一致的文件,文件内容就是我们编辑的定时脚本。

如:

[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:

使用命令 vi /etc/crontab 编辑定时脚本。

如:

[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 ,这样系统也会帮着检查我们配置的脚本语法。

posted @ 2017-06-01 20:57  Big_Foot  阅读(739)  评论(0编辑  收藏  举报