- 1 SUSE Linux Enterprise Server for SAP Comes to IBM Power
- 2 VMware Hints at Potential Evolution for Container Strategy
- 3 Windows Server 2003 Meets the Zombie Apocalypse
- 4 Tips and Considerations When Creating Virtual Machines in Azure
- 5 Securing Containers without the Need for Virtualization Technology
Why Cron Is Better Than a String Around Your Finger
I've occasionally found it useful to set up reminders to be emailed to myself on a regular basis. The most straightforward tool to use for this is cron with mail.Tip of the Trade: Mailing reminders to yourself is an easy way to remember something that easily slips your mind. Using Cron with mail is one way to facilitate this.
If you're sending directly from the command line, this command:
mail -s "Subject test" email@example.com
will not actually send the mail straight away. Instead, it will wait for you to type in the body of the email (which can be empty), and hit Ctrl-D twice. This may be a nuisance if you want an empty mail body and the message to be sent immediately. To mitigate that, you can try this:
mail -s "Subject test" firstname.lastname@example.org < /dev/null
If you're sending mail from cron, however, mail is running noninteractively, and it will behave slightly differently. On my (Debian stable) system, I don't need that redirect. Just using this line in the crontab:
59 8 * * 1-5 mail -s "Check backup ran" email@example.com
will send the mail at the appropriate time (0859 on Monday-Friday) with any empty body and without any intervention. However, this may vary between systems depending on exactly what program the mail command runs. On my system, this is /usr/bin/bsd-mail via a couple of soft links. If you do have problems, try adding the /dev/null input pipe as it appears on the command-line.
You may also want to redirect any output, which you can do by adding a redirect in the other direction:
59 8 * * 1-5 mail -s "Check backup ran" firstname.lastname@example.org > /dev/null
If you want to send an email that does have a body (e.g., the contents of a logfile), try:
15 4 * * * mail -s "Today's logs" email@example.com < /var/log/messages
In fact, if you want a regular log email, LogWatch is a better choice. But you can use this to create any mail body: Just write and save an appropriate file.