Automating Email Reminders to Yourself
Emailing With Myself
If you're sending directly from the command line, this command:
mail -s "Subject test" firstname.lastname@example.org
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" email@example.com < /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" firstname.lastname@example.org
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" email@example.com > /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" firstname.lastname@example.org < /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.
Article courtesy of ServerWatch
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: Alienware, KDE and Ubuntu 13.04
- 2Linux Top 3: Linux Mint Olivia, Fedora 19's Cat and Ubuntu's Mission Accomplished Moment
- 3GNOME 3.8 Debuts New Open Source Linux Desktop
- 4Linux Top 3: Linux 3.10 Goes Long, Linux 3.11 Advances as LXDE Merges
- 5Linux Top 3: Ubuntu Kaylin, Debian Wheezy and Linux Mint