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




目录
相关文章
|
9天前
|
安全 Ubuntu Java
Linux配置使用篇
Linux配置使用篇
|
17天前
|
Linux Shell
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
70 1
|
21天前
|
存储 负载均衡 索引
linux7安装elasticsearch-7.4.0集群配置
linux7安装elasticsearch-7.4.0集群配置
109 0
|
26天前
|
存储 Shell Linux
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
30 1
|
8天前
|
Linux 网络安全
linux免密登录报错 Bad owner or permissions on /etc/ssh/ssh_config.d/05-redhat.conf
linux免密登录报错 Bad owner or permissions on /etc/ssh/ssh_config.d/05-redhat.conf
17 1
|
9天前
|
网络协议 Linux
在Linux中,管理和配置网络接口
在Linux中管理网络接口涉及多个命令,如`ifconfig`(在新版本中被`ip`取代)、`ip`(用于网络设备配置)、`nmcli`(NetworkManager的CLI工具)、`nmtui`(文本界面配置)、`route/ip route`(处理路由表)、`netstat/ss`(显示网络状态)和`hostnamectl/systemctl`(主机名和服务管理)。这些命令帮助用户启动接口、设置IP地址、查看连接和路由信息。不同发行版可能有差异,建议参考相应文档。
19 4
|
8天前
|
Linux
Linux Crontab 查看定时任务启动没
Linux Crontab 查看定时任务启动没
15 0
Linux Crontab 查看定时任务启动没
|
17天前
|
Linux Shell 开发工具
linux编辑文件出现write.error.(file.system.full?)
linux编辑文件出现write.error.(file.system.full?)
10 1
|
19天前
|
网络协议 Linux 网络安全
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
17 0
|
26天前
|
存储 Linux Shell
【Shell 命令集合 系统设置 】Linux 配置和管理时区 timeconfig命令 使用指南
【Shell 命令集合 系统设置 】Linux 配置和管理时区 timeconfig命令 使用指南
37 0