浅谈Linux配置定时,使用crontab -e与直接编辑/etc/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 ,这样系统也会帮着检查我们配置的脚本语法。

以上这篇浅谈Linux配置定时,使用crontab -e与直接编辑/etc/crontab的区别就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

参与评论