简体   繁体   English

Linux sendmail命令在cron中不发送邮件

[英]Linux sendmail command not sending mail while in a cron

I'm trying to run a sendmail command in a Red-hat Linux environment on a bash shell script through a cronjob. 我正在尝试通过cronjob在bash shell脚本上的Red-hat Linux环境中运行sendmail命令。 I can run this script successfully when it is ran manually and every other job within the shell runs correctly other than the mailing part.I have never used sendmail and am not sure if I need to restructure how it is being presented. 当手动运行该脚本并且外壳中的所有其他作业(除了邮件部分)正常运行时,我都可以成功运行该脚本。我从未使用过sendmail,并且不确定是否需要重组其呈现方式。

I have tried mail and mailx. 我已经尝试过mail和mailx。 I am able to send the emails but the log file contain many weird characters that it put the text format into a att00001.bin attachment on the email which I do not want. 我能够发送电子邮件,但是日志文件包含许多奇怪的字符,因此将文本格式放入我不需要的电子邮件的att00001.bin附件中。 The sendmail command seems to be the only one that doesn't send an attachment when ran manually. sendmail命令似乎是手动运行时唯一不发送附件的命令。 Other cron jobs works correctly and are able to send emails they just do not have the special characters in the log file. 其他cron作业可以正常工作,并且能够发送电子邮件,但它们在日志文件中没有特殊字符。

echo '##################################################'
date
echo '##################################################'

#Run Script and write to log file
/comp/gfb281m.sh > /usr/local/bin/oracle/getload/getload.log 2>&1

#Send log file to developer group
(echo "Subject:GetLoad Shell"; echo; cat 
/usr/local/bin/oracle/getload/getload.log) | sendmail -v 
exampleEmail@outlook.com exampleEmail2@mail.mil

When ran this cron job should send the contents of the getload.log file to a group a of users. 运行此cron作业后,应将getload.log文件的内容发送给一组用户。

Fixed the issue thanks to another source. 通过另一个来源修复了此问题。 I was not using the sendmail's full path. 我没有使用sendmail的完整路径。 I was just stating "| sendmail -v email" and not sendmails full path which was "/usr/sbin/sendmail" for me. 我只是说“ | sendmail -v电子邮件”,而不是sendmails的完整路径,对我来说是“ / usr / sbin / sendmail”。 Not sure if links are allowed here but below is where I found the answer. 不知道这里是否允许链接,但是下面是我找到答案的地方。

https://www.unix.com/red-hat/271632-bash-sendmail-command-not-found.html https://www.unix.com/red-hat/271632-bash-sendmail-command-not-found.html

crontab sets PATH to /usr/bin:/bin . crontab将PATH设置为/usr/bin:/bin To avoid typing absolute command names like /etc/sbin/sendmail you can set up the PATH in you crontab: 为了避免输入绝对命令名称,例如/etc/sbin/sendmail您可以在crontab中设置PATH:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/30 * * * * sendmail user@example.com%subject: Sample email%%Email body%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM