Reputation: 736
I want to echo text as well as tail the last part of a log to pipe it to email. I can easily do one or the other, but how do I do both without first writing everything to a file and then emailing that? I basically want to combine the below two commands into one to only send out one email.
echo "There is an error in the log, see the below for detail" | mail -s "error in the log" [email protected]
and
tail -n 10 /var/log/error.log | mail -s "error in the log" [email protected]
Thanks.
Upvotes: 0
Views: 1448
Reputation: 46
You could use the concatenate command along with process substitution:
cat <(echo "There is an error in the log, see the below for detail") <(tail -n 10 /var/log/error.log) | mail -s "error in the log" [email protected]
Upvotes: 1