I have created restart.sh with followin code
#!/bin/bash
ps -aux | grep sidekiq > /dev/null
if [ $? -eq 0 ]; then
echo "Process is running."
else
echo "Process is not running."
fi
To check if sidekiq process is running or not. I will put this script in cron to run daily so if sidekiq is not running, it will start automatically.
My problem is, with
ps -aux | grep sidekiq
even when the process is not running, it shows
myname 27906 0.0 0.0 10432 668 pts/0 S+ 22:48 0:00 grep --color=auto sidekiq
instead of nothing. This gets counted in grep hence even when the process is not running, it shows as "sidekiq" process is running. How to not count this result ? I believe I have to use awk but I am not sure how to use it here for better filtering.