Linux配置定时,使用crontab -e与直接编辑/etc/crontab的区别
2017-04-10 10:47:45   来源:   评论:0 点击:

Linux配置定时,使用crontab -e与直接编辑 etc crontab的区别
crontab这个系统功能,但有时候我们需要区分用户执行,下面就直接说一下2种方法的区别:

方法1:

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

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

如:

 
1
2
3
4
5
6
7
8
[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 编辑定时脚本。
 

如:

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[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 ,这样系统也会帮着检查我们配置的脚本语法

相关热词搜索:用crontab -e与直接编辑 etc crontab

上一篇:Linux中文显示乱码?如何设置centos显示中文
下一篇:最后一页

分享到: 收藏