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

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -