This question already has an answer here:
- Sending a mail from a linux shell script 9 answers
I am on linux machine and I monitor a process usage. Most of the time I will be away from my system and I have access to internet on my device. So I planned to write a shell-script that can mail me the output of the process.
Is it possible?
If so how to make a shell-script send me mail?
Please provide a snippet to get started.
Well, the easiest solution would of course be to pipe the output into mail:
I guess
sh test.sh &
will do just as fine normally.(
/file/with/mail/content
should be a plaintext file, not a file attachment or an image, etc)Basically there's a program to accomplish that, called "mail". The subject of the email can be specified with a -s and a list of address with -t. You can write the text on your own with the echo command:
or get it from other files too:
mail doesn't support the sending of attachments, but Mutt does:
Note that Mutt's much more complete than mail. You can find better explanation here
PS: thanks to @slhck who pointed out that my previous answer was awful. ;)
Yes it works fine and is commonly used:
sendmail
works for me on the mac (10.6.8)