簡體   English   中英

如何將多行 output 重定向到 mailx 郵件正文?

[英]How to redirect multiline output into mailx body of message?

我正在嘗試將命令的 output 重定向到 mailx。

if grep -B 1 line $curccrtpick; then
    grep -B 1 line $curccrtpick | head -2 > tempmsg
    mail -s "String found in $curccrtpick" -r test@test.com dummy@test.com < tempmsg
    #rm tempmsg
else
    echo nothing
fi

但它顯示為附件形式的二進制文件(ATT00001.bin)

當我跑

tr -d '[\015\200-\377]' < tempmsg > tempmsg1

並將該文件重定向到 mailx 我收到 email 在一個襯里:

thefirstlinethesecondline

什么時候應該有兩個

thefirstline
thesecondline

這是對我有用的邏輯。 使用 sendmail 似乎比使用 mailx 更合適。

if grep -B 1 Retry $curpickccsb; then
        stringLine1=$(grep -B 1 Line $curpickccsb | head -1)
        stringLine2=$(grep Line $curpickccsb | head -1)
        echo -e "String located in $curpickccsb. Sending email notification."
        echo -e "Content-Type: text/plain\r\nFrom: no-reply@domain.com\r\nSubject: String in $curpickccsb\r\n\r\n'$stringLine1'\r\n'$stringLine2'\r\n" | sendmail -f no-reply@domain.com test@domain.com
else
        echo -e "No errors located in $curpickccsb"
fi

暫無
暫無

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

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