Below is my script and this script is design to work to check if "python3.6" process is running.
If it is not running then execute python code else exit 0.
I don't see any activity or process running of python from this bash script.
please help me to understand if i scripted something wrong.
Any help is greatly appreciated.
Thanking in advance.
#!/bin/bash
ps x |grep -v grep |grep -c "python3.6"
if [ $? -eq 0 ]; then
bash -c "/home/ubuntu/anaconda3/bin/python3.6 /var/lib/pythoncode/main_progm.py >> /home/ubuntu/Logs.txt"
fi
# End of Script
ps x |grep -v grep |grep -c "python3.6"to your question.-c.grep -cnever exits with an error, whether found or not (as long as there wasn't something else like missing file that caused one), and$?is always0regardless of how the search went.grepneeds to succeed at searching;grep -cneeds to succeed at counting. I have no idea why your code wouldn't be running, because I'd expect it to run always (ignoring whether or notgrepfound anything).grep -cwill have areturnof1if the input is empty. (e.g.echo "" | grep -c "python3"returns1)'$?'return are two different things...