Talk about the difference between using crontab e and directly editing and etc and crontab when Linux is configured for timing

  • 2020-05-13 04:23:13
  • OfStack

Linux configuration timing task, we all know to use crontab this system function, but sometimes we need to distinguish between user execution, let's directly say the difference between 1 and 2 methods:

Method 1:

Use the command crontab-e and edit the timing script directly.

After this execution, the user-defined file will be written to /var/spool/cron, and a file with the username 1 will be generated. The file content is the timing script we edited.

Such as:


[root@localhost cron.d]# cd /var/spool/cron
[root@localhost cron]# ll
 The total amount  4
-rw-------. 1 root root 52 12 month  9 10:58 root
[root@localhost cron]# pwd
/var/spool/cron
[root@localhost cron]# cat root 
30 03 * * * /root/automysqlbackup.sh

Method 2:

Edit the timing script using the command vi /etc/crontab.

Such as:


[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 ~]# 

System level configuration we will configure /etc/crontab directly

It is still recommended to use crontab-e (user level) 1, so that the system will also help to check the syntax of our configured scripts.


Related articles: