这应该相对简单,但我以前从未遇到过,现在我摸不着头脑。
简单的脚本:
echo `tail /var/log/qmailcheck.log` >> $EMAIL
cat $EMAIL | mail -s "Daily server report from server.ca" email@here.com
(我知道我在tail
cmd 周围缺少一组刻度,只是想让事情看起来正确)
问题是,虽然我要拖尾的日志文件为每个条目都有一个新行,但发送的电子邮件将所有内容都放在一行上,而不是这样:
Mon Feb 4 11:05:01 MST 2013-- Check Completed Successfully
Mon Feb 4 11:10:01 MST 2013-- Check Completed Successfully
Mon Feb 4 11:15:01 MST 2013-- Check Completed Successfully
Mon Feb 4 11:20:01 MST 2013-- Check Completed Successfully
Mon Feb 4 11:25:01 MST 2013-- Check Completed Successfully
我明白了:
Mon Feb 4 11:05:01 MST 2013-- Check Completed Successfully Mon Feb 4 11:10:01 MST 2013-- Check Completed Successfully Mon Feb 4 11:15:01 MST 2013-- Check Completed Successfully Mon Feb 4 11:20:01 MST 2013-- Check Completed Successfully Mon Feb 4 11:25:01 MST 2013-- Check Completed Successfully
该脚本还从许多其他命令中回显,它们似乎也遇到了一行,我以前做过,但从来没有遇到过问题,我错过了什么?
这是整个脚本:
ERROR=/tmp/errorlog
RECIP=$(cat /root/bin/emailrec)
echo Hi, this email to inform you of any potential issues with the server.bla qmail mail server > /tmp/demail
grep pls /var/log/qmailcheck.log > /tmp/errorlog
if [ ! -s $ERROR ] ; then
echo There are no errors in the qmailcheck log file >> /tmp/demail
echo Here are the last 10 lines of the current qmailcheck log file: >> /tmp/demail
tail /var/log/qmailcheck.log >> /tmp/demail
else
echo The log file for the qmail check script contains the following errors: >> /tmp/demail
cat $ERROR >> /tmp/demail
echo You should have also received an email which will better explain the error >> /tmp/demail
echo Check the time of the error above to determine when the email was sent >> /tmp/demail
fi
MAIL=$(/var/qmail/bin/qmail-qstat | grep "queue:" | awk '{ print $4 }')
echo There are $MAIL messages in the mail queue >> /tmp/demail
echo File system usage is currently at `df -h |grep vzfs | awk '{ print $5}'` >> /tmp/demail
cat /tmp/demail | mail -s "Daily server report from server.bla" $RECIP