This is an old revision of the document!
Send output of crontab via email with sendmail
This guide shows how to configure a crontab script to send it's output via email.
Thereby that the MAILTO=
setting in crontabs is global, it's not that easy to send an email to a different address from another crontab files.
The crontab should then look like this:
/path/to/crontab
#!/bin/bash RECIPIENT=user@example.com SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) SCRIPT_NAME=$(basename "$0") SENDER=root@$(/bin/hostname) crontab () { echo "From: $SENDER" echo "Subject: Cron <$SENDER> $SCRIPT_DIR/$SCRIPT_NAME " echo "To: $RECIPIENT" # Commands to be run here echo "" echo "Crontab location: $SCRIPT_DIR/$SCRIPT_NAME" } crontab | sendmail -t $RECIPIENT