Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for something that I'm sure is out there, but I can't find it.

I have a long running program (Matlab simulation) that runs for 24 hours or more on the Mac in my office. Occasionally the program crashes, so I'm looking for a program or command that can periodically check to make sure the process is still running, and if it is not, send me an email so I can log in remotely and restart the program/fix the problem.

The more user-friendly the better, as I'd like non-advanced users to be able to use it on their own.

share|improve this question
1  
I don't know if there's such a program, but how about this: Use launchd (with StartInterval) to periodically launch a script, use ps to find the process you're looking for, mailx or Mail.app scripting to send mail. –  Daniel Beck Nov 16 '10 at 23:14
add comment

3 Answers 3

If you want to keep a process running (or, rather, restart it if it exits) use launchd. There's a recipe for keeping TextEdit alive here, and Lingon is available as a GUI to set it up.

This isn't perfect for your particular problem, though - launchd will restart your process whenever it exits, regardless of whether it was successful or not. This could be a big pain if your program were to overwrite the perfectly good output from the previous run. To get round this, you could wrap your program in a script (a shell script would do) that would run the program, then, if it was successful, remove the launchd job before exiting. Something like:

#!/bin/bash

/my/matlab/program
#$? is the exit value of your program - convention is 0 for success, non-zero otherwise
if [ $? = 0 ]
    launchd unload keep.my.matlab.running
fi

[edit]

If Matlab produces output as fideli suggests, you could use a folder action on the folder that Matlab would put its error report into. Simply write an Applescript or Automator workflow that takes the files that have been added, checks if they are a Matlab error and, if so, sends you an e-mail. One of the built-in ones is called "new item alert" and is probably a good starting point for some genetic modification.

share|improve this answer
add comment

I haven't used Matlab in a while, but from what I understand from MathWorks support, if your code crashes you would get a matlab_crash_dump.XXXX file in your home folder, where XXXX is a number. You can then use Hazel to detect the addition of that file and then use an Automator workflow to send you an email.

I would have liked to test this but don't currently have anything that crashes Matlab.

share|improve this answer
add comment

You could accomplish this with a simple script. Any script you're comfortable with, be it bash, ruby, applescript or whatever.

I had a bash script set on a cron job that would check if a Teamspeak server was running and if not, start it.

share|improve this answer
1  
Understand a script could do this, I was just hoping there was a utility out there, that was a little more user friendly, and would let me be lazy and not have do much more than pointing and clicking :) –  Millhouse Nov 16 '10 at 23:37
    
Ugh. Pointing and clicking is so much work. Wouldn't you rather just type a few keystrokes? –  user31752 Nov 17 '10 at 0:30
add comment

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.