如何测试crontab条目? [英] How to test crontab entry?

查看:311
本文介绍了如何测试crontab条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的crontab中有一个条目,如下所示:

I have an entry in my crontab that looks like this:

0 3 * * * pg_dump mydb | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz

当我从外壳执行该脚本时,该脚本运行完美,但似乎并非每天晚上都在运行。我假设权限有问题,也许crontab在其他用户下运行或其他原因。我该如何调试?我是一个共享的托管环境(WebFaction)。

That script works perfectly when I execute it from the shell, but it doesn't seem to be running every night. I'm assuming there's something wrong with the permissions, maybe crontab is running under a different user or something. How can I debug this? I'm a shared hosting environment (WebFaction).

推荐答案

您需要使用反斜杠对crontab条目中的%字符进行转义-请参见crontab(5)联机帮助页。我遇到了完全相同的问题。

You need to escape "%" characters in crontab entries with backslashes- see the crontab(5) manpage. I've had exactly the same problem.

例如:

0 7 * * * mysqldump usblog | bzip2 -c > usblog.$(date --utc +\%Y-\%m-\%dT\%H-\%M-\%SZ).sql.bz2

您没有收到cron错误的电子邮件吗?即使将 MAILTO=you@example.com放在crontab中也没有?

Do you not get emails of cron errors? Not even if you put "MAILTO=you@example.com" in the crontab?

如果没有pg_dump或gzip,则可能还需要在crontab中设置PATH。在系统默认路径上(因此请使用 type pg_dump检查它们的位置,crontab通常通常只在/ bin或/ usr / bin中运行命令)

You may also need to set PATH in your crontab if pg_dump or gzip isn't on the system default path (so use "type pg_dump" to check where they are, crontab usually only runs commands in /bin or /usr/bin by default)

这篇关于如何测试crontab条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆