Finding out how long a script runs for and exit reason.

I am running a daemon program that sends texts via a connected mobile phone. I run this daemon via CLI, and it loops a few commands (checking to see if there are any new texts).

It runs perfectly, the problem is, when I leave this to run on my Ubuntu Desktop, and come back to it hours later it has stopped running.

I need to find out why it exited, and when, so I can write a cron task to start it up periodically. - how do i do this best?

Thanks.

Set return codes at exit points, and put this at the top of your script:

LOGFILE=/path/to/logfile ## adjust to taste
trap 'date >> "$LOGFILE"' EXIT

hey thanks alot for the code.

problem is i didnt make the daemon so i cannot put return codes at exit points.

I think it may be more ideal to check if the process is running or not, then if it isnt restart it.

ive started a new thread to make things more clearer!