簡體   English   中英

郵件命令將錯誤日志文件作為附件而不是在 Linux 中的正文中發送

[英]Mail command sending the error log file as attachment instead of in the Body in Linux

我在使用 mail 命令從 Linux 機器發送電子郵件時遇到問題。 它不像在正文中那樣發送錯誤日志,而是作為 .bin 格式的附件發送。 在少數情況下,它在身體中發送。 以下是我嘗試通過電子郵件作為正文發送的日志詳細信息。 是不是因為日志中的“/”等特殊字符作為 .bin attachemnt 發送的。 我可以使用 sendmail 來解決這個問題,但我們想使用 mail 命令發送它。

引起:org.springframework.integration.MessagingException:上傳文件時無法寫入'/DBSInboundandOutbound/prod/outbound/DSP/PartsMaster/PartsMasterFull_NNANissanV5124_20211015071711.xml.gz.tmp'。將“/DBSInboundandOutbound/prod/outbound/DSP/PartsMaster/PartsMasterFull_NNANissanV5124_20211015071711.xml.gz.tmp”重命名為/DBSInboundandOutbound/prod/outbound/DSP/PartsMaster/PartsMasterFull5.212171217120101712171717171710 服務器回復:550 'PartsMasterFull_NNANissanV5124_20211015071711.xml.gz.tmp':無法重命名。 2021-10-15 02:01:49,342 錯誤 | dbs-intg-scheduler-18 | cndjadapter.support.MDCFatalErrorChannelInterceptor | [DBS] 致命錯誤 [org.springframework.integration.MessageDeliveryException: 文件 [/datapp/common/batch_datafile/parts/P-16/outComingFolder/PartsMasterFull_NNANissanV5124_20211015071711.xml.gz] 的錯誤處理消息] -orgagingException.springwork : 上傳文件時無法寫入“/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" 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM