How to check if JBoss is running on Unix server?

58,025

Solution 1

Instead of checking the output, just use the command:

if pgrep -f jboss >/dev/null
  then
  echo "jboss is running"
else
  echo "jboss is not running"
fi 

Solution 2

Get the process ID JBoss 7 / EAP 6:

pgrep -f org.jboss.as

So if you want to enhance the former example script with this:

if [ -z "$(pgrep -f org.jboss.as)" ]
then 
 echo "JBoss is NOT running"
else
  echo "JBoss is running"
fi 

Solution 3

Try using the exit status of the command -

#!/bin/bash

pgrep -f jboss &> /dev/null
if [ $? -eq 0 ]
  then
  echo "jboss is running"
else
  echo "jboss is not running"
fi

Solution 4

This is the best way:

if [ -z "$(ps -ef | grep java | grep jboss)" ]
then 
 echo "JBoss is NOT running"
else
  echo "JBoss is running"
fi

Solution 5

#! /bin/bash
 if [ -z "$(ps -ef | grep org.jboss.Main)" ]
then 
 echo "jboss is not running"
else
  echo "jboss is running"
fi
Share:
58,025
user1060096
Author by

user1060096

Updated on July 05, 2022

Comments

  • user1060096
    user1060096 almost 2 years

    I have a script below that I'd like to echo out "jboss not running" or "jboss is running" depending on whether it can find the jboss process in the process list. However, when I shut down Jboss it still executes the Else condition and says "jboss is running". If I manually do "pgrep -f jboss" it doesn't return anything, so why is it still going into the Else condition? puzzled

    #!/bin/bash
    if [ -z "$(pgrep -f jboss)" ]
      then
      echo "jboss is not running"
    else
      echo "jboss is running"
    fi 
    

    Thanks for your help!

  • itsbruce
    itsbruce over 11 years
    You haven't answered his question; you just explained why his check isn't good enough to monitor jboss.