配置 /etc/crontab 后 crontab 不工作
crontab doesn't work after /etc/crontab is configured
我将这一行添加到 /etc/crontab 文件的末尾:
* * * * * cp /etc /backups -R > /dev/null && tar -Jcf /backups/etc-`date +\%Y-\%m-\%d-\%H-\%M-\%S`.tar.xz /backups/etc > /dev/null && rm -rf /backups/etc > /dev/null
然后我用 systemctl restart crond
命令重启了 crond 服务
但没用
当我在终端运行这个命令cp /etc /backups -R > /dev/n......
时有效
我的 root 邮箱是空的。
谁能告诉我我的配置有什么问题吗?
非常感谢!!!
/etc/crontab
不是普通的 crontab 文件;这是一个 system crontab 文件。每行通常有 5 个字段指定时间表,然后是第 6 个字段指定帐户。使用您在 /etc/crontab
中显示的行,它将尝试 运行 作为用户 cp
的命令。
如果您正在使用 Vixie cron 实现(您可能正在使用),运行 man 5 crontab
并搜索“EXAMPLE SYSTEM CRON FILE”。
我建议不要触摸 /etc/crontab
。而是使用 crontab
命令为您想要的任何帐户创建用户 crontab。 运行 crontab
as root
如果命令开始 运行 需要 root 权限。
我觉得现在可以了
[root@localhost public]# crontab -e
crontab: installing new crontab
[root@localhost public]# systemctl restart crond
[root@localhost public]# crontab -l
* * * * * cp /etc /backups -R > /dev/null && tar -Jcf /backups/etc-`date +\%Y-\%m-\%d- \%H-\%M-\%S`.tar.xz /backups/etc > /dev/null && rm -rf /backups/etc > /dev/null
[root@localhost public]#
我将这一行添加到 /etc/crontab 文件的末尾:
* * * * * cp /etc /backups -R > /dev/null && tar -Jcf /backups/etc-`date +\%Y-\%m-\%d-\%H-\%M-\%S`.tar.xz /backups/etc > /dev/null && rm -rf /backups/etc > /dev/null
然后我用 systemctl restart crond
命令重启了 crond 服务
但没用
当我在终端运行这个命令cp /etc /backups -R > /dev/n......
时有效
我的 root 邮箱是空的。
谁能告诉我我的配置有什么问题吗? 非常感谢!!!
/etc/crontab
不是普通的 crontab 文件;这是一个 system crontab 文件。每行通常有 5 个字段指定时间表,然后是第 6 个字段指定帐户。使用您在 /etc/crontab
中显示的行,它将尝试 运行 作为用户 cp
的命令。
如果您正在使用 Vixie cron 实现(您可能正在使用),运行 man 5 crontab
并搜索“EXAMPLE SYSTEM CRON FILE”。
我建议不要触摸 /etc/crontab
。而是使用 crontab
命令为您想要的任何帐户创建用户 crontab。 运行 crontab
as root
如果命令开始 运行 需要 root 权限。
我觉得现在可以了
[root@localhost public]# crontab -e
crontab: installing new crontab
[root@localhost public]# systemctl restart crond
[root@localhost public]# crontab -l
* * * * * cp /etc /backups -R > /dev/null && tar -Jcf /backups/etc-`date +\%Y-\%m-\%d- \%H-\%M-\%S`.tar.xz /backups/etc > /dev/null && rm -rf /backups/etc > /dev/null
[root@localhost public]#