gpt4 book ai didi

linux - 无法弄清楚 cron 电子邮件的去向

转载 作者:太空宇宙 更新时间:2023-11-04 12:19:25 25 4
gpt4 key购买 nike

我有一个使用 xubuntu 16.04 的开发箱。我已设置 ssmtp 来处理邮件并可以发送电子邮件。我用

测试了它
 mail myemail@mydomain.com < .~/.bashrc' 

而且效果很好。我有一个 cron 作业每分钟运行一次,它创建的输出应该由我的 cron 发送。 'grep CRON/var/log/syslog' 给我

 Sep 27 15:22:01 epdev CRON[19569]: (eventpuddle) CMD (cd /home/eventpuddle/eventpuddle/batch; ./scrape_check_todays_logs.bash )
Sep 27 15:22:01 epdev sSMTP[19571]: Creating SSL connection to host
Sep 27 15:22:01 epdev sSMTP[19571]: SSL connection using RSA_AES_128_CBC_SHA1
Sep 27 15:22:03 epdev sSMTP[19571]: Sent mail for root@sun.prsc (221 2.0.0 Bye) uid=1000 username=eventpuddle outbytes=816

如果我“sudo -i”并输入邮件,我会被告知没有邮件。/etc/ssmtp/ssmtp.conf 是:

root=myemail@mydomain.com
mailhub=mail.myhoestingpeople.com:2525
hostname=sun.prsc
UseSTARTTLS=YES
AuthUser=user
AuthPass=password
FromLineOverride=YES
UseTLS=YES

cronent 是

* * * * *  ( cd /home/eventpuddle/eventpuddle/batch; ./scrape_check_todays_logs.bash ) 

./scrape_check_todays_logs.bash 是

 #!/bin/bash 
# scrape_check_todays_logs.bash (c) 2017 Ben Edwards (http://funkytwig.com/it)
# Check logfiles for today and email them if there are any errors.

. ~/.bashrc

[ -z "$HOME" ] && { echo '$HOME not set'; exit 1; }
[ -z "$ADMIN_EMAIL" ] && { echo '$ADMIN_EMAIL not set'; exit 1; }

t=/tmp/`basename $0 .bash`.$$.tmp
d=$HOME

grep -l "$d" log/*`date +%A`* > $t

cat $t | while read line
do
echo "mail $line"
mail -s "eventpuddle batch failuure $line" $ADMIN_EMAIL < $line
done

grep EXCLUD log/*`date +%A`* > $t

mail -s 'eventpuddle exclusions' $ADMIN_EMAIL < $t

不确定要提供什么其他信息,但如果被问到会提供。

最佳答案

从外观上看,您似乎正试图将电子邮件转发到外部电子邮件地址? SSMTP 用于将警报转发到外部电子邮件。你有SSMTP设置吗?配置(/etc/ssmtp/ssmtp.conf)应该是这样的

# The user that gets all the mails (UID < 1000, usually the admin)
root=username@gmail.com

# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
# See also https://support.google.com/mail/answer/78799
mailhub=smtp.gmail.com:587

# The address where the mail appears to come from for user authentication.
rewriteDomain=gmail.com

# The full hostname. Must be correctly formed, fully qualified domain name or GMail will reject connection.
hostname=yourlocalhost.yourlocaldomain.tld

# Use SSL/TLS before starting negotiation
UseTLS=Yes
UseSTARTTLS=Yes

# Username/Password
AuthUser=username
AuthPass=password
AuthMethod=LOGIN

# Email 'From header's can override the default domain?
FromLineOverride=yes

Ubuntu 有一个关于如何设置它的很好的文档 - here

关于linux - 无法弄清楚 cron 电子邮件的去向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46450553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com