troubleshooting Question

Remove grep usage ouput

Avatar of saharey
saharey asked on
Shell Scripting
6 Comments1 Solution383 ViewsLast Modified:
Before starting my tomcat server I want to see that "server.pid" file is not present and also that the no process is running with PID mentioned in this server.pid,
Scenario is  when ‘server.pid’ file is not present then I get this grep usage output, this happens while executing “start” or “status” arg

./serv.sh status
+ status
++ isRunning
++ '[' '!' -z /home/psaharey/XLRISoftware/XLRI/cdp/bin/server.pid ']'
+++ cat /home/psaharey/XLRISoftware/XLRI/cdp/bin/server.pid
++ SEARCH=
+++ /bin/ps -ef
+++ grep
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information
.
+++ grep -v grep
++ RESULT=
++ '[' -n '' ']'
++ echo 0
+ RET=0
+ '[' 0 -eq 0 ']'
+ echo 'The server is stopped'
The server is stopped

I want to go away with this usage output, can anyone help me out in this reagard.
My “isRunning” function looks like this
 
isRunning ()
{
   #PID=`cat "$CATALINA_PID" 2>/dev/null`
   if [ ! -z "$CATALINA_PID" ]; then
      SEARCH=`cat "${SERVER_PID}" 2>/dev/null`
    else
      SEARCH=$CATALINA
   fi
   RESULT=`${PS} | grep $SEARCH | grep -v grep 2>/dev/null`
   if [ -n "${RESULT}" ]; then
      # if we are here, then server is running
      echo 1
   else
      # if we are here, then server is not running
      echo 0
   fi
}
ASKER CERTIFIED SOLUTION
DonConsolio

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros