我有一个使用 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
cront 输入是
* * * * * ( 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
不确定要提供哪些其他信息,但如果被问到会。