我创建了一个 shell 脚本,它每天进行备份,并通过电子邮件将其执行成功或失败发送出去。现在我希望它也能随邮件发送它创建的日志文件的内容。我已经了解了如何将文件作为附件发送,但我想将文件的内容作为电子邮件消息发送,而不是文件本身。请帮忙。
它的代码就像
#Email Settings
Message_Success="Database Backup generated successfully"
Message_Failure="Problem occured while generating Database Backup please verify"
Subject="Database Backup Status Mail"
Recipients="[email protected]"
#Verify Backup Created
if [ -f "$Path_Mysql_Dump" ]; then
echo "Database Backup Created" >> $Path_Log_File
echo "$Message_Success" | mail -s "$Subject" "$Recipients"
else
echo "Database Backup not created please verify the process will terminate" >> $Path_Log_File
echo "$Message_Failure" | mail -s "$Subject" "$Recipients"
exit -1
fi
答案1
为什么不
{ echo -e "$Message_Success\n\n" ; cat $Path_Log_file ; } | mail -s "$Subject" "$Recipients"