发送错误日志文件作为附件的邮件命令,而不是在Linux的正文中



我在使用邮件命令从Linux盒子发送电子邮件时遇到了问题。它不是像Body那样发送错误日志,而是以.bin格式作为附件发送。而在少数情况下,它是把身体送进去的。下面是我试图通过电子邮件作为身体发送的日志细节。是因为"/"这样的特殊字符吗?在日志中,它以.bin附件的形式发送。我可以使用sendmail来解决这个问题,但是我们想使用邮件命令发送它。

所致:org.springframework.integration.MessagingException:未能写'/DBSInboundandOutbound/刺激/出站/DSP/PartsMaster PartsMasterFull_NNANissanV5124_20211015071711.xml.gz.tmp"同时上传文件造成的:java.io.IOException:重命名失败'/DBSInboundandOutbound/刺激/出站/DSP/PartsMaster PartsMasterFull_NNANissanV5124_20211015071711.xml.gz.tmp"/DBSInboundandOutbound/刺激/出站/DSP/PartsMaster PartsMasterFull_NNANissanV5124_20211015071711.xml.gz"。服务器回复:550 'PartsMasterFull_NNANissanV5124_20211015071711.xml.gz.tmp':无法重命名。[DBS]致命错误[org.springframework.integration.MessageDeliveryException:文件[/datapp/common/batch_datafile/parts/P-16/outComingFolder/PartsMasterFull_NNANissanV5124_20211015071711.xml.gz]的错误处理消息]-org.springframework.integration.MessagingException:日志含义写入'/DBSInboundandOutbound/prod/outbound/DSP/PartsMaster/PartsMasterFull_NNANissanV5124_2021101507171 '失败1.xml.gz.tmp'上传文件

mContent=`cat $1`
msgimp=$2
mailsub=$3
monitor=$4
logname=$5
echo  >> /datapp/common/operation_admin/monitor/monitor_log/$mailsub.txt
echo $mContent  >> /datapp/common/operation_admin/monitor/monitor_log/$mailsub.txt

mail -s "[Prod] [$monitor] [$msgimp] [$mailsub] found in $logname log" -r "DBS Production 
Alert <noreply@*******.com>" alert.*********.com < 
/datapp/common/operation_admin/monitor/monitor_log/$mailsub.txt
rm -f /datapp/common/operation_admin/monitor/monitor_log/$mailsub.txt
mContent=`cat $1`
...
echo $mContent  >> /datapp/common/operation_admin/monitor/monitor_log/$mailsub.txt

此时,$mailsub.txt的内容与不一样$1的含量。mContent变量是不加引号的因此,所有的空格序列(包括换行符!)都会被一个空格取代。所以邮件正文是一行。

我在这里猜测,但如果这一行很长,我可以想象电子邮件系统的某些部分会改变消息,将正文移动到附件中。

我不明白为什么有必要读取输入文件,将它(错误地)写入一个新文件,将新文件的内容发送出去,然后删除新文件。试试这个:

mData=$1
subject=$(printf "[Prod] [%s] [%s] [%s] found in %s log" "$4" "$2" "$3" "$5")
from="DBS Production Alert <noreply@*******.com>"
to="alert.*********.com"
mail -s "$subject" -r "$from" "$to" < "$mData" 

最新更新