On my Synology DS215j I have a scheduled task, that is executed every 5 minutes and checks, if a specific python script is running:
Works principially fine, but the execution of the task never ends (except the python script crashes). So, I tried to start it in background
#!/bin/bash # Import environment variables ... . /etc/profile PYSCRIPT="telegram-bot.py" if ! ps ax | grep -q "$PYSCRIPT"; then echo "$PYSCRIPT is running" else echo "$PYSCRIPT not running, attempting to start..." cd /volume1/homes/Python exec python3 "$PYSCRIPT" echo "$PYSCRIPT started!" fi
exec python3 "$PYSCRIPT" &. But with this change, there is a huge disadvantage included, this line
if ! ps ax | grep -q "$PYSCRIPT"; thennow always returns FALSE, so that the python-script is started again and again...