我设置了一个 cronjob,在失败时向我发送电子邮件。问题是它来自Cron Daemon
并且主题是Cron <ubuntu@ip-10-100-21-10> /home/ubuntu/neo/bin/backup-test.sh >> /home/ubuntu/neo/logs/log-test.out
我这样做的方法是使用这一行:MAILTO="[email protected]"
如何修改sender
并subject
使其更简洁一些?
答案1
我在备份脚本的末尾添加了以下几行,以便发送包含之前收集的日志的电子邮件。
mailbody=${log}
echo "From: Backup xx <[email protected]>" > /tmp/backupmail
echo "To: [email protected]" >> /tmp/backupmail
echo "Subject: [BACKUP] Failure report for $(hostname)" >> /tmp/backupmail
echo "" >> /tmp/backupmail
cat ${mailbody} >> /tmp/backupmail
cat /tmp/backupmail | /usr/sbin/sendmail -t