[英]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.