Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Curious if there is an easy way to send a background email alert if a Time Machine backup fails (or continuously fails rather than just one time)

I've found TM Error Logger however, it cannot run in the background, and also generates the email through the systems default mail client, which then needs to be manually sent.

Ideally I'd like a solution that does this in the background without any input or action from the end user - so that I can be notified if their machines aren't backing up.

The trouble is many users don't realize that Time Machine may not be working for them - they don't know to look for the "!" in the TM menu bar icon (or often what it means)

share|improve this question
    
If you want more robustness you should investigate in making the mail system on the machine work properly. This will allow you to buffer mails if the outgoing connection for any reason is down. –  Thorbjørn Ravn Andersen Oct 6 '12 at 22:03

3 Answers 3

This is a great use case for a simple shell or python or ruby script and launchd.

I'll assume you can find on this site how to configure the launchd item or want to buy Lingon which is a great timesaver. (Be aware Lingon 3 is for Lion and there is another also paid version for Snow Leopard just named Lingon on the App store)

You also will need to set up an internal mail server that accepts command line mail from all your clients, so there is that large chunk of setup.

With all that "hand waving" to explain broad concepts - you now could use these core commands to get the job done:

  • tmutil latestbackup
  • date "+%Y-%m-%d"
  • mail -s "TimeMachine Failure Report from $HOSTNAME" "This mac needs attention"

Depending on how much fun this sounds, you can pick apart each task and work on them or look into software that is designed to do this for you like Apple Remote Desktop or Robot Cloud.

share|improve this answer
    
Thanks - that's a great answer, however I'm hoping for something simpler, and ideally prepackaged. I guess where it could fall apart is on the emailing side, since it would require SMTP credentials to successfully send email –  Josh Newman Nov 16 '11 at 22:08
1  
The last two links I put in the article are pre-packaged solutions. ARD is scriptable with Automator or Apple Script so you can easily pull the information. The other is a software as a service that is incredibly powerful and $5 per monitored machine. –  bmike Nov 16 '11 at 23:03

As bmike says, you can use lingon. or manually make you own launch agent

Here is a test example. My time machine device was not plugged in. So backups would fail.

I used an applescript saved as text and with the osascript shebang at the top.

    #!/usr/bin/osascript
property i_The_Sender : "senderAddress1@ip.com"
property theAddress2 : "recipientAddress@ip.com"
set userNAME to ""
tell application "System Events"
    set userNAME to full name of current user
end tell
property theSubject : "TimeMachine Failure Report from "

set tm to do shell script "/usr/bin/syslog -F '$Time $Message' -k Sender com.apple.backupd -k Time ge -59m | tail -n 3"

if tm contains "failed" then
    set otherLog to do shell script "/usr/bin/syslog -F '$Time $Message' -k Sender com.apple.backupd-helper -k Time ge -59m | tail -n 20"
    tell application "Mail"
        set newMessage to make new outgoing message with properties {subject:(theSubject & userNAME), content:tm & return & otherLog}
        tell newMessage

            set visible to false
            set sender to i_The_Sender
            make new to recipient at end of to recipients with properties {address:theAddress2}

            send --<<<<---------------- change save to send to send or send to save to save in drafts

        end tell
    end tell

end if

This means I can run the Applescript as a native shell script.

The script will also send the email in the background. It does launch mail.app but not in focus. Nor will it bring mail.app to focus if mail.app is already running.

chmod the applescript text file as you would a normal wheel script file to give it execute permissions .ie. chmod a+x /path/tp/file

Using lingon: choose the file and you run options. Save and load. If you do it manually then place the file you launch agent file in ~/Library/LaunchAgents/

enter image description here

share|improve this answer

Time Machine failing - get alerted by Growl I think it already says it. But okay... I wrote a script which checks the age of the last successful time machine backup and alerts by growl if it is too old.

share|improve this answer
    
Welcome to Ask Different! Answers on Ask Different need to be more than just a link. It's okay to include a link, but please summarize or excerpt it in the answer. –  gentmatt Oct 6 '12 at 22:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.