Linux 通过电子邮件发送差异输出和电子邮件正文
我的Bash脚本中有以下代码。如何将正文添加到电子邮件中? 示例:Body:outputLinux 通过电子邮件发送差异输出和电子邮件正文,linux,email,unix,diff,Linux,Email,Unix,Diff,我的Bash脚本中有以下代码。如何将正文添加到电子邮件中? 示例:Body:output diff -q file1 file2 || diff file1 file2 | mail -s "subject" "email@email.com" 假设您有一个mail程序,该程序能够理解用于附加文件(如s-nail或mailx)的-a if ! diff -q file1 file2; then diff file1 file2 > something.diff echo
diff -q file1 file2 || diff file1 file2 | mail -s "subject" "email@email.com"
假设您有一个
mail
程序,该程序能够理解用于附加文件(如s-nail或mailx)的-a
if ! diff -q file1 file2; then
diff file1 file2 > something.diff
echo 'body' | mail -s 'subject' -a something.diff 'email@email.com'
rm -f something.diff
fi
可以使用Bash的进程替换来避免临时文件
diff -q file1 file2 || echo 'body' | mail -s 'subject' -a <(diff file1 file2) 'email@email.com'
diff-qfile1 file2 | | echo'body'| mail-s'subject'-a我就是这么做的
difference=` diff file1 file2 >/dev/null || diff file1 file2`
if [ -n "$difference" ]; then
mail -s " subject " "address" <<EOF
Body here
$difference
Body here
EOF
fi
difference=`diff file1 file2>/dev/null | | diff file1 file2`
如果[-n“$difference”];然后
邮件-s“主题”“地址”您有什么版本的mail
?一些,例如,支持一个-a
选项来附加文件。sendmail-8.14.4-9.el6_8.1.x86_64真的吗?这不可能是rpm-qf/usr/bin/mail
所说的,sendmail
不提供二进制文件。(这是MTA,不是MUA。)在CentOS上,您可能已经安装了mailx
。执行rpm-qa | grep sendmailYes,但这对于mail
命令并不重要。如果您要这样做,那么{echo'Body here';diff file1 file2;echo'Body here';}| mail-s'subject''address'
更好,因为它不需要将diff作为字符串加载到Bash中。(当然,您可以用cat替换echo
)