Restart python script automatically even when it crashes in Linux

0 votes

I have a python program that has to be running all the time. If for some reason it was stopped I want to restart it automatically. I thought of having a cron that will run every n number of seconds and check the program is running. My shell script is looks like this:

#!/usr/bin/env bash
CM_COMMAND=`ps aux| grep abc| grep def| grep sudo`
LEN_COMMAND=${#CM_COMMAND}
if[["$LEN_COMMAND" -le "5"]] 
then
    echo "start the python program"
fi
exit

When I run this script I am getting the error: my_prog.sh: line 4: $'if[[118\r -le 5]]\r': command not found'

What is the alternative of doing this and what is the problem with my script?

Sep 11, 2018 in Python by bug_seeker
• 15,520 points
3,752 views