Job Monitor


I have set up my monitor for the pi zero.
Logging into the pi zero this morning I noticed that the python job had stopped.
This means that I need to come up with some scheduled chron job to watch it and make sure it is running.
It should be simple enough.
First, comes checking the process.
It truns out that a simple command "pidof python" may work.
Since it is only running a single script, just checking for python running should do the trick.

Interestingly, I also came across another command where you can check the internal temp of the pi.
/opt/vc/bin/vcgencmd measure_temp. I can probably use this later to do a comparison between the temp from the gmc-320 radiation monitor and the temp of the unit. The gmc is showing 26.8c while the unit temp is 37.9c.
Since it is i a pi zero, I do not have any heat sync's or fans but may add the heat sync later.

ps -c python shows a bit more data like CMD,TTY but I don't really need it, all I need is to see if there is a PID (process ID) assigned for a python task.
"pidof python" simply returns 29504 which is the PID. If I shut down the script it returns nothing, so there is my validation that quickcpm is still running.

so I am thinking this should be simple.
The bool: Fire off the pidof command. value=true, no value=false. If true, end. If false run python and end. Set it up as a chron job to run every 10 minutes.
Initially I had installed scheduledtasks as my gui for checking the tasks but I think this time I will attempt it from command line.

What I came up with is the following script that I called
I found some info and a script at :

To be able to run (executable) it I had to type the command:
sudo chmod +x

ps cax | grep python > /dev/null
if [ $? -eq 0 ]; then
echo "QCPM is running."
echo "Starting QCPM."
x-terminal-emulator -e python /home/pi/bin/quickcpm/
exit -f

I used x-terminal-emmulator so that it would launch in a new window.

Here is the crontab (crontab -e)
45 23 * * * python3.5 /home/pi/bin/quickcpm/ # JOB_ID_1
0 * * * * /home/pi/bin/ >/dev/null 2>&1 # JOB_ID_2

The first job runs the monthly task for quickCPM python script.
The second ob checks that it quickCPM is running and starts if it has stopped.

-6.1193329,39.1580149,06-17-2019 10:00:25 AM,!Walking the dog