将自定义消息和 grep 一起传递给 mutt

pipe custom message and grep together to mutt

我想 grep 一个日志文件并通过 mutt 将它发送到我的电子邮件地址。 另外,我想用我的电子邮件发送一条短信。

echo | grep "ERROR" logFile.log  | mutt -s "ERROR Messages" myemail@gmail.com -a logFile.log

这很好用。我 grep 我的日志文件并在我的电子邮件中将其作为正文回显到 myemail@gmail.com 并附上日志文件。 但我还想在我的 grep 输出中添加一条消息,例如:“这是一封自动生成的电子邮件”。 怎么管呢?

理解mutt

echo "This is the body" | mutt -s "Testing mutt" user@yahoo.com -a /tmp/XDefd.png

我使用的是 grep 的输出而不是 "This is the body",但我也想在其中添加自定义消息。

您可以在子进程中执行多个命令并将整个输出通过管道传输到 mutt:

(cat fixedmessage.txt;
 grep "ERROR" logFile.log) |
mutt -s "ERROR Messages" myemail@gmail.com -a logFile.log