Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 431  / 2 Years ago, tue, july 19, 2022, 3:03:55

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`

More From » 12.04

 Answers
2

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:



zfs snapshot Misu@Misu-`date +%Y.%m.%d-%H:%m:%S`


most probably gives you an error, so you must to use:



25 11 * * 5 /home/aegrimisu/ZFS-autosnapshot.sh>>/home/aegrimisu/ZFS-WeeklySnapShot.log 
| mail -s "ZFS SnapShot Status" [email protected]


as crontab if you want to receive the error by e-mail.


[#30015] Wednesday, July 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tialmes

Total Points: 14
Total Questions: 108
Total Answers: 102

Location: Oman
Member since Thu, Jun 16, 2022
2 Years ago
;