I would like to create a shell script to prevent a python script from crashing in a Raspberry Pi. This python script is auto started on reboot with cron, however, sometimes it can crash while running.
Currently my shell script reads:
#!/bin/sh
COMMAND='python home/pi/projects/mypythonscript.py'
LOGFILE=restart.txt
writelog() {
now=`date`
echo "$now $*" >> $LOGFILE
}
writelog "Starting"
while true ; do
$COMMAND
writelog "Exited with status $?"
writelog "Restarting"
done
I wanted to ask if I can create two command lines, in order to make sure two independent scripts can be prevented from crashing with this shell script? Or do I have to make a new shell script file for the second python script?
I am thinking of modifying it this way:
#!/bin/sh
COMMAND1='python home/pi/projects/mypythonscript1.py'
COMMAND2='python home/pi/projects/mypythonscript2.py'
LOGFILE=restart.txt
writelog() {
now=`date`
echo "$now $*" >> $LOGFILE
}
writelog "Starting"
while true ; do
$COMMAND1
$COMMAND2
writelog "Exited with status $?"
writelog "Restarting"
done
Would this modification work? I appreciate any advice as I am still quite new to the linux (debian) platform.
COMMAND1
, wait for it to terminate, then startCOMMAND2
, and also wait for it to terminate, before it repeats that cycle. Are you sure this is intended?