所有行在电子邮件中一起运行 [英] All lines running together in email

查看:143
本文介绍了所有行在电子邮件中一起运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个应该比较简单,但我从来没有遇到过,现在我正在抓我的头。



简单脚本:

  echo`tail / var / log / qmailcheck.log`>> $ EMAIL 
cat $ EMAIL | mail -sserver.ca的每日服务器报告email@here.com

(我知道我在$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $虽然我拖延的日志文件对于每个条目都有一个新的行,所发送的电子邮件将所有内容都放在一行,而不是这样:



Mon Feb 4 11:05:01 MST 2013--检查成功完成

Mon Feb 4 11:10:01 MST 2013--检查成功完成

Mon Feb 4 11 :15:01 MST 2013--检查成功完成

Mon Feb 4 11:20:01 MST 2013--检查成功完成

Mon Feb 4 11:25:01 MST 2013 - 检查成功完成



我得到这个:

Mon Feb 4 11:05 :01 MST 2013--检查已成功完成Mon Feb 4 11:10:01 MST 2013--检查成功完成Mon Feb 4 11:15:01 MST 2013--检查成功完成Mon Feb 4 11:20:01 MS T 2013 - 检查已成功完成Mon Feb 4 11:25:01 MST 2013--检查已成功完成



该脚本还从其他命令的数量,他们似乎也跑到一行,我以前做过,但从来没有一个问题,我错过了什么?



这是整个脚本:

  ERROR = / tmp / errorlog 
RECIP = $(cat / root / bin / emailrec)

echo您好,这封电子邮件通知您有关server.bla qmail邮件服务器的任何潜在问题> / tmp / demail

grep pls /var/log/qmailcheck.log> / tmp / errorlog

如果[! -s $ ERROR];然后
echo qmailcheck日志文件中没有错误>> / tmp / demail
echo这里是当前qmailcheck日志文件的最后10行:>> / tmp / demail
tail /var/log/qmailcheck.log>> / tmp / demail
else
echo qmail检查脚本的日志文件包含以下错误:>> / tmp / demail
cat $ ERROR>> / tmp / demail
echo你应该也收到一个电子邮件,这将更好地解释错误>> / tmp / demail
echo检查上述错误的时间以确定何时发送电子邮件>> / tmp / demail
fi
MAIL = $(/ var / qmail / bin / qmail-qstat | grepqueue:| awk'{print $ 4}')
echo有$邮件队列中的MAIL邮件>> / tmp / demail

echo文件系统使用情况目前为`df -h | grep vzfs | awk'{print $ 5}'`>> / tmp / demail


cat / tmp / demail | mail -sserver.bla的每日服务器报告$ RECIP


解决方案

这是您不需要任何一个时使用echo 命令替换所得到的。



/ p>

  echo`command args ...`

 命令args 
pre>

是换行符已折叠(代码更难阅读)。只需使用

  tail /var/log/qmailcheck.log | mail -s .... 

(如果要使用中间文件,则可以使用它也没有 echo 或反引号)。



请注意,命令替换有另一种风格: $(command ...),它摆脱了嵌套引用的问题,通常更易读。每当你想要命令替换,你可以使用这种风格,而不是反引号。


This should be relatively simple but I've never run into it before and now I'm scratching my head.

Simple script:

echo `tail /var/log/qmailcheck.log` >> $EMAIL
cat $EMAIL | mail -s "Daily server report from server.ca" email@here.com

(I know I'm missing a set of ticks around the tail cmd just wanted things to look right)

The problem is that although the log file I'm tailing out has a new line for every entry the email that gets sent puts everything onto one line so instead of this:

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

I get this:
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

The script also echo's from a number of other commands and they also seem to run into one line as well, I've done this before but never had an issue, what am I missing?

Here's the entire script:

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

解决方案

That's what you get for using echo and command substitution when you don't need either of them.

The only distinction between

echo `command args...`

and

command args

is that the newlines are collapsed (and the code is harder to read). Just use

tail /var/log/qmailcheck.log | mail -s ....

(If you want to use an intermediate file, then you can use it too without echo or backticks).

Note that there is another style for command substitution: $(command...), which gets rid of problems with nested quoting and is generally more readable. Whenever you want command substitution, you can use this style instead of backticks.

这篇关于所有行在电子邮件中一起运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆