I am trying to check if a process (assume it is called some_process
) is running on a server. If it is, then echo 1, otherwise echo 0.
This is the command that I am using but it only works partially (more info below). Note that I need to write the script in one line.
ps aux | grep some_proces[s] > /tmp/test.txt && if [ $? -eq 0 ]; then echo 1; else echo 0; fi
Note: The [s]
in some_proces[s]
is to prevent grep
from returning itself.
If some_process
is running, then "1"
gets echoed, which is fine. However, if some_process
is not running, nothing gets echoed.