For some time now, I have come across a trivial but annoying problem: I have to send out some periodic emails to admins, to inform them that I'd be utilizing certain resources. But writing the same email every time is painful to say the least.
So here's a little trick to automate the sending task on Linux, provided that the sendmail program has been installed (it mostly is). One way to test that is to send a fake email to yourself, by checking if you received it. On a terminal, type:
echo "did I get this?"| mail -s "test" yourName@yourDomain.com
If you do get the email message with subject "test" and content "did I get this", then the first step towards automated emails is to type out the email content and save it in to a file (which we call emailContent here). The rest is easy: the command to send it is the following:
mail -s "SubjectOfTheEmail" recipient1@someDomain.com recipient2@someDomain.com < emailContent
The line above can be added to shell script, which can then be executed whenever necessary. What is even cooler, is that now email can be sent from a program written in a scripting language (like Perl) by simply calling the script.
For the extremely lazy sorts, even the execution of the shell script can be automated, using the cron job scheduler.
More information on mail, cron can be obtained from the man pages (type 'man mail' or 'man cron' on a terminal) or google for them.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment