当我通过命令行运行命令时,Linux crontab查找并通过电子邮件收到EOF结果
问题描述:
工作正常,我在附加的* .txt文件中得到具有所需结果的电子邮件。然而,当cron运行这个相同的命令时,我收到一个EOF错误。当我通过命令行运行命令时,Linux crontab查找并通过电子邮件收到EOF结果
任何人都可以指出什么可能会导致此错误?
我在CentOS运行的cPanel与Cloudlinux 6.6
下面是我从cron收到说它出错的电子邮件;
Subject: Cron <[email protected]> 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
答
必须逃脱%:
man (5) crontab:
Percent-signs (%) in the command, unless escaped with backslash (\),
will be changed into newline characters, and all data after the
first % will be sent to the command as standard input.
+0
非常感谢! DOH! ;) – uhhm
'cron'运行作为不同的用户,所以'/家庭/帐户名/'...不会被人指指点点,你认为它是。另外,如果使用'mailx'作为'mail',它包含'-a'选项以允许您将文件而不是'uuencode'和管道附加到消息。检查你是否有可用的选项(例如'mail -s“...”-a $(date +'%m-%d-%Y') - accountname-filescan.txt') –
我认为, ,你最好把它放在一个文件中,比如说'/ usr/local/etc/file-scan-report',然后只需要'01 * * * */usr/local/etc/file-scan-报告'在crontab中。 –
@ DavidC.Rankin - 我尝试使用你提到的'mail -a'选项,并且至少说出了一些奇怪的结果 - 我确实发现我不需要'uuencode'。感谢您的建议。 ;) – uhhm