【发布时间】:2016-05-07 18:09:23
【问题描述】:
当我通过命令行运行命令时,它工作正常,我在附加的 *.txt 文件中收到带有所需结果的电子邮件。但是,当 cron 运行相同的命令时,我收到 EOF 错误。
谁能指出可能导致此错误的原因?
我在 CentOS 上使用 Cloudlinux 6.6 运行 CPanel
这是我从 cron 收到的电子邮件,说它出错了;
Subject: Cron <root@whm> find /home/accountname/public_html -type f -mtime -7 2> `date +'
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
这是我的命令;
01 * * * * find /home/accountname/public_html -type f -mtime -7 2> `date +'%m-%d-%Y'`-accountname-filescan.txt | uuencode `date +'%m-%d-%Y'`-accountname-filescan.txt | mail -s "`date +'%m-%d-%Y'`-accountname File Scan Report" root
对于我做错的任何建设性意见,我将不胜感激。
我按照这个线程来开发我的命令; Linux cron job to email output from a command
【问题讨论】:
-
cron以不同的用户身份运行,因此/home/accountname/... 不会指向您认为的位置。此外,如果您将mailx用作mail,它包含-a选项以允许您附加文件而不是uuencode并通过管道传输到消息。检查您是否有可用的选项(例如mail -s "..." -a $(date +'%m-%d-%Y')-accountname-filescan.txt) -
我认为如果有这么长的内容,最好将所有内容都放在一个文件中,比如
/usr/local/etc/file-scan-report,然后在 crontab 中添加01 * * * * /usr/local/etc/file-scan-report。 -
@DavidC.Rankin - 我尝试使用您提到的
mail -a选项,但至少可以说它导致了一些奇怪的结果 - 我确实发现我不需要uuencode。谢谢你的建议。 ;) -
@JohnHascall 感谢我今天实现了一个脚本的建议,与编辑超长的 cron 条目相比,编辑脚本要容易得多! =)