linux - See if a service is running with exit code -
I have created a simple script that checks whether the service is running and the exit code is coming back, but I It can not work. If this works, and exits 1, then it is not.
#! / Bin / bash # To check if the SSH service is running SERVICE = 'ssh' if [ps aux | Grep -v grep | Grep $ SERVICE & gt; / Dev / null]; Then exit if statement 0 and exit 1fi
< P> just
ps aux | Can be replaced with Grep -v grep | Grep -q "$ SERVICE" The exit status of the pipeline is 0 if the grep -q succeeds (i.e., ssh ), and 1 else if this is the last line of the script, then the shell exit will be the same: exit is no requirement for explicit calls.
Comments
Post a Comment