欢迎光临
嗟嗟嗟~じぇじぇじぇ!~(''jjj'')/

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

inux配置定时任务,大家都知道使用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 [email protected]::resource /hyy/bak/resource
30 4 * * * root /usr/bin/rsync -vzrtopg --progress --delete [email protected]::log /hyy/bak/log
############################################
[root@localhost ~]#

(系统级的)做系统级配置我们会直接配置 /etc/crontab

(用户级的)一般还是建议大家使用 crontab -e ,这样系统也会帮着检查我们配置的脚本语法。

赞(5)
未经允许不得转载:嗟嗟嗟 » Linux配置定时,使用 crontab -e 与 直接编辑 /etc/crontab 的区别
分享到: 更多 (0)

评论 抢沙发

2 + 9 =
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址