Reputation: 5
Read=$((ps -eaf | grep "$name" | grep -v grep | awk '{print $1}'))
Read1=$((ps -p <$Read>))
if [ $Read1 -ne 0 ]; then
exit 1
This is what I get so far, I want to first get the pid of the $name, then check whether there is process corresponding to that pid. If there is not, exit 1.
I am not sure about this.
Upvotes: 0
Views: 639
Reputation: 2093
This is what I would use for this purpose:
test="$(ps aux | grep -sie "process-name" | grep -v "grep -sie")"
if [ -z "$test" ]; then exit 1; else echo "Process found ----- $test"; fi
This code is case insensitive (ex.: it would match "process-name" but also "Process-NAME").
Upvotes: 0