I have a weekly script that cron runs to make a zfs snapshot. I was wondering if it is possible to mail a OK mail if the job run correctly and a error mail if something happened and in the content of the mail to have the job log. How to do this?
25 11 * * 5 /home/aegrimisu/ZFS-autosnapshot.sh>>/home/aegrimisu/ZFS-WeeklySnapShot.log 2>&1 | mail -s "ZFS SnapShot Status" [email protected]
The script content is :
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
zfs snapshot Misu@Misu-`date +%Y.%m.%d-%H:%m:%S`
2>&1
tells the shell to redirect standard error to standard output. Without it, you would still get e-mails if the script printed anything on standard error.This line from your
ZFS-autosnapshot.sh
script:most probably gives you an error, so you must to use:
as crontab if you want to receive the error by e-mail.
Variant with Mutt E-Mail Client
Install mutt
sudo apt-get install mutt
Create mailbck.sh and paste the lines from http://pastebin.ubuntu.com/5965821/
Make it executable
chmod +x mailbck.sh
Adapt it for your needs