I want to check if a command is running with the following if
clause, but it's always true
, whether command actually is running or not:
if [ $"(ps aux | grep curl)" ]; then echo is; else echo not; fi
Result:
[root@is ~]# if [ $"(ps aux | grep curl)" ]; then echo is; else echo not; fi
is
The ps
command outside of if
:
[root@is ~]# ps aux | grep curl
root 216564 0.0 0.2 6408 2064 pts/0 S+ 22:22 0:00 grep --color=auto curl
How can I check if curl
in my example is running or not?
I tried with different arguments of ps
, but I always have the grep
command (which is normal in my mind), but I don't know how to check that if it's running or not.
Update 1
I'm thinking that I can do this but I don't know how to do this in commands:
if ps aux blah
if it has only one line (I suppose somehow use `wc -l`
then do something
else do something else
fi
fi
grep
to filter the firstgrep
pgrep curl
just work for you?pgrep curl
works and I tried with both runningcurl
and killing PID. Thanks. Please write it as an answer.ps aux | grep curl | grep -v grep
pgreg curl
is shorter thanps aux | grep curl | grep -v grep
. But Thanks for the comment and answer.