【问题标题】:Mail command sending the error log file as attachment instead of in the Body in LinuxMail 命令将错误日志文件作为附件发送,而不是在 Linux 的正文中发送
【发布时间】:2021-10-22 14:51:55
【问题描述】:

我在使用 mail 命令从 Linux 机器发送电子邮件时遇到问题。它不是像在正文中那样发送错误日志,而是以 .bin 格式作为附件发送。在少数情况下,它发送的是身体。以下是我尝试通过电子邮件作为正文发送的日志详细信息。是因为它作为.bin附件发送的日志中的“/”等特殊字符吗?我可以使用 sendmail 来解决这个问题,但我们想使用 mail 命令发送它。

原因:org.springframework.integration.MessagingException:上传文件时无法写入'/DBSInboundandOutbound/prod/outbound/DSP/PartsMaster/PartsMasterFull_NNANissanV5124_20211015071711.xml.gz.tmp' 原因:java.io.IOException :无法将“/DBSInboundandOutbound/prod/outbound/DSP/PartsMaster/PartsMasterFull_NNANissanV5124_20211015071711.xml.gz.tmp”重命名为/DBSInboundandOutbound/prod/outbound/DSP/PartsMaster/PartsMasterFull_NNANissanV5124_20211015071711.xml.gz'。服务器回复:550'PartsMasterFull_NNANissanV5124_20211015071711.xml.gz.tmp':无法重命名。 2021-10-15 02:01:49,342 错误 | dbs-intg-scheduler-18 | c.n.d.j.adapter.support.MDCFatalErrorChannelInterceptor | [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" &gt;&gt; filename
  • 记得引用所有变量。

标签: linux shell mailx


【解决方案1】:
mContent=`cat $1`
...
echo $mContent  >> /datapp/common/operation_admin/monitor/monitor_log/$mailsub.txt

此时,$mailsub.txt 的内容与$1 的内容不一样。 mContent 变量是unquoted,因此所有的空格序列(包括换行符!)都被一个空格替换。所以电子邮件的正文是一长串。

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

我不明白为什么需要读取输入文件,将其(错误地)写入新文件,邮寄新文件的内容,然后删除新文件。试试这个:

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" 

【讨论】:

  • 我一提交就意识到了。
猜你喜欢
  • 2015-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-19
相关资源
最近更新 更多