Usually when one wants to keep track of one’s cron jobs, one tells the cron daemon to email the output of the commands. While this is probably the best solution for servers, on desktop machines is problematic. Many ISPs block outgoing traffic on port 25 (SMTP), and if you want to send the emails via external SMTP server (such as GMail) this requires you to store authentication details in plain text. A better solution for the desktop would be to harness the desktop notifications available in Ubuntu.
There is a useful tool called
notify-send which is able to send desktop notifications directly from the command line. However, there are few caveats:
notify-sendexpects its input on the command line, it can’t read from
- If you run from cron you must tell it which display to use.
The first issue can be worked around by using cat to pick up the input. The second issue is handled by adding a
DISPLAY environment variable to the crontab. So your crontab will look something like this:
DISPLAY=:0 10 1 * * sun some_cool_command | notify-send "Backup Documents" "$(cat)"
The first argument to
notify-send is the title of the notification. The second is the actual text to appear in it, in our case it’s whatever comes in the
stdin. If you want to store the output in a log file as well as displaying it in a desktop notification, you can use
tee, which basically saves its input to a given file and also pipes it again to
DISPLAY=:0 10 1 * * sun some_cool_command | tee -a ~/some_log.log | notify-send "Backup Documents" "$(cat)"