Friday, October 28, 2022

[SOLVED] How to check weather tomcat server ist started up

Issue

I want to check if tomcat server is really started up. When you start tomcat, you get an entry like "Server startup" in catalina.out. Once I got this, the script should go ahead.

That's my code

 echo "Waiting for Tomcat"
 if [ $(tail -f /home/0511/myapp/logs/catalina.out | grep "Server startup" | wc -l) -eq 1 ]; then
    echo "Tomcat started"
 fi
#further code...

Output:

Waiting for Tomcat
|

So, I am sure, after 30-60 seconds, the "tail .. | wc -l" gets 1. However, I cannot match it with my code above. Nothing happens, I have to interrupt per CTRL C.

What is wrong or is there any better solution for my intention?


Solution

Try this:

while true;do
  if tail -n 100 /home/0511/myapp/logs/catalina.out | grep -q "Server 
    startup";then
    echo "Tomcat started"
    exit 0
  fi
done

So you constantly check the last 100 lines from the log, and if match, exit with a message.

There are other solutions to this, but this is closest to what you already have



Answered By - Ron
Answer Checked By - David Marino (WPSolving Volunteer)