How do I execute a python script in the background if it is not already running? An example use for this is on the cron.
if you want a script to start once at startup and theoretically it stays up then you should add it as a service to init.d with the appropriate runlevel set.
Of course if it should go down then you would want to to come back up.
to do that you can have a shell script run ps -aux | grep 'nameOfYourScript' like that. Of course don't include the grep command which will match as well lol. have that script check every five minutes with a cron like this */5 * * * * user checkScript.sh
the checkScript you make could be written to start up the program.
You could do something like this:
Put this in crontab or start with
nohup will make sure that the process isnt shutdown if you exit the ssh session. An alternative to this is