On Wed, Jan 24, 2007 at 02:51:50AM +0000, Paul Pruett wrote:
> Using cron and atactl to email smartstatus errors
> to an email address other than cron user:
> -----------------------------------------
> 
> 
> I was playing with the suggesion in the man
> page for atactl and smart status. After using rc.local
> to make sure smart is enabled, something like
>  echo -n 'wd0: '
>  /sbin/atactl wd0 smartenable
>  /sbin/atactl wd0 smartstatus
> 
> Now to put someting in crontab to hourly check for errors,
> per suggestion of man page for atactl I could use:
> 0 * * * * /sbin/atactl /dev/wd0c smartstatus >/dev/null
> 
> And the error will email to root, or if the variable
> [EMAIL PROTECTED]
> Then all error messages from cron will go there :(
> 
> I can see where I might want some tasks to email
> standard error messages to other than the cron user or MAILTO,
> like sending an email to a pager or other alert email box.
> Thus the question, how to edit cron task to send normal output to null
> but email error messages...  Handling outputs if I rember
> and a quick google found a page that seems to confirm,
> http://ibmdocs.ncep.noaa.gov/userman/cron.html
> suggests 1> should be standard and 2> should be errors
> so we should be able to do something like
> 
> 0 * * * * /sbin/atactl /dev/wd0c smartstatus 1>/dev/null 2>mail -s "wd0 
> ERRORS on serverXYZ" [EMAIL PROTECTED]
> 
> 
> Other than using up your pager allotment, does anyone see
> a problem doing it this way, please correct.
> 
> 
> If a server is not raid, and using cheaper ide/sata drives,
> this might be a useful way to be urgently notifed of
> a hard drive that may fail.

You'd need to use

0 * * * * /sbin/atactl /dev/wd0c smartstatus 2>&1 >/dev/null | \
        mail -s "wd0 ERRORS on serverXYZ" [EMAIL PROTECTED]

but aside from that, it sounds okay. Of course, Damien's solution is
superior if atactl is halfway sane software.

(Note the pipe; you need to do something like that to get the data to
the mail command, and this is the most portable. Also note that 1 in 1>
is not necessary, as that's the default, and that 2>&1 redirects stderr
tot stdout.)

You'll most probably end up writing a script anyway, if you want this to
work on several servers.

                Joachim

Reply via email to