Reputation: 133
I have this bash script that start the python script ms.py What is the problem here ?
#!/bin/bash
if [ $(ps aux | grep -e 'ms.py$' | grep -v grep | wc -l | tr -s "\n") -eq 0 ];
then python /root/folder/ms.py &
fi
and this in my crontab
*/1 * * * * /root/folder/script.sh
When I start the script manually it works normal.
Upvotes: 1
Views: 133
Reputation: 246774
you are testing the output of that pipeline against the number zero. I assume you want to start your python program only if it's not already running:
pid=$(pgrep -f 'ms.py$')
if [[ $pid ]] && kill -0 $pid; then
echo already running
else
echo not running
python /root/folder/ms.py &
fi
Upvotes: 1