Search code examples
grepcommand-line-interfaceechomutt

pipe custom message and grep together to mutt


i want to grep a logfile and send it via mutt to my email address. Additionally i would like to send an text with my email.

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

This works fine. I grep my logfile and echo it as body in my email to myemail@gmail.com with the logfile attached. But i would also like to add an message like : " This is an automatic email generated" additionally to my grep output. How to pipe it ?

To understand mutt :

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

instead of "This is the body" iam using the output of grep but i would also like to put an custom message in it.


Solution

  • You can execute several commands in a subprocess and pipe the whole output to mutt:

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