shell - Cron 不执行。脚本工作正常

标签 shell unix cron

我有一个压缩日志文件的 crontab。

crontab -e 我有 -I'm root-:

5 3 * * 6 find /toMyLogs -name "access*" -a ! -name '*.bz2' -ctime +7 -exec bzip2 -zv {} \;
35 3 * * 6 find /toMyLogs -name "error*" -a ! -name '*.bz2' -ctime +7 -exec bzip2 -zv {} \;

日志示例如下:

$ ls -la /toMyLogs
-rw-r--r--   1 root     root       33317 Jul  2 19:04 error_1.log.2012-07-02
-rw-r--r--   1 root     root       12928 Jul  3 08:55 error_2.log.2012-07-03

如果我手动执行命令,这是:

find /toMyLogs -name "access*" -a ! -name '*.bz2' -ctime +7 -exec bzip2 -zv {} \;

它有效,但在 cron 中无效。我用示例文件(不是日志)做了一些小型测试,然后运行了 cron。 有效。因此,cron 确实在运行。

你知道发生了什么事吗?权限还是时间?

最佳答案

当您运行 cron 时,环境设置不同。很有可能cron使用的PATH没有找到bzip2程序。

Reasons why crontab does not work

关于shell - Cron 不执行。脚本工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11312043/

相关文章:

macos - OSX 终端命令移动目录中的所有文件

linux - 如何使用 awk 命令验证文件的内容?

c - 读取描述符的非阻塞调用

unix - 什么是交换文件?

linux - 部署使用 cron 的网络应用程序

bash - "source"shell 脚本中的命令不起作用

bash - 如何在bash单行中传递两个参数?

bash - 在给定的时间内,Cron 作业和随机时间

php - cron mysqldump 说不使用密码

php - 如何在 ubuntu 中运行这个 bash 脚本?