【问题标题】:Linux crontab find and email results receiving EOFLinux crontab 查找和电子邮件结果接收 EOF
【发布时间】: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 条目相比,编辑脚本要容易得多! =)

标签: linux email cron


【解决方案1】:

你必须转义 %:

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.

【讨论】:

  • 非常感谢!哦! ;)
猜你喜欢
  • 1970-01-01
  • 2017-12-24
  • 2013-06-07
  • 1970-01-01
  • 2021-08-31
  • 1970-01-01
  • 1970-01-01
  • 2010-10-18
  • 2021-08-25
相关资源
最近更新 更多