Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8536917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:46:37+00:00 2026-06-11T10:46:37+00:00

I am trying to get a shell script to recognize when an app instance

  • 0

I am trying to get a shell script to recognize when an app instance has come up. That way it can continue issuing commands.

I’ve been thinking it would be something like this:

#/bin/bash

startApp.sh

while [ `tail -f server.log` -ne 'regex line indicating success' ]
do

sleep 5

done

echo "App up"

But, even if this worked, it wouldn’t address some concerns:

  • What if the app doesn’t come up, how long will it wait
  • What if there is an error when bringing the app up
  • How can I capture the log line and echo it

Am I close, or is there a better way? I imagine this is something that other admins have had to overcome.

EDIT:

I found this on super user

https://superuser.com/questions/270529/monitoring-a-file-until-a-string-is-found

tail -f logfile.log | while read LOGLINE
do
   [[ "${LOGLINE}" == *"Server Started"* ]] && pkill -P $$ tail
done

My only problem with this is that it might never exit. Is there a way to add in a maximum time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:46:38+00:00Added an answer on June 11, 2026 at 10:46 am

    Ok the first answer was close, but didn’t account for everything I thought could happen.

    I adapted the code from this link:

    Ending tail -f started in a shell script

    Here’s what I came up with:

    #!/bin/bash
    
    instanceDir="/usr/username/server.name"
    serverLogFile="$instanceDir/server/app/log/server.log"
    
    function stopServer() {
    
        touch ${serverLogFile}
    
        # 3 minute timeout.
        sleep 180 &
        local timerPid=$!
    
        tail -n0 -F --pid=${timerPid} ${serverLogFile} | while read line 
        do
            if echo ${line} | grep -q  "Shutdown complete"; then
              echo 'Server Stopped'
              # stop the timer..
              kill ${timerPid} > /dev/null 2>&1
            fi
        done &
    
        echo "Stoping Server."
        $instanceDir/bin/stopserver.sh > /dev/null 2>&1
    
        # wait for the timer to expire (or be killed)
        wait %sleep
    
    
    }
    
    function startServer() {
    
        touch ${serverLogFile}
    
        # 3 minute timeout.
        sleep 180 &
        local timerPid=$!
    
        tail -n0 -F --pid=${timerPid} ${serverLogFile} | while read line 
        do
            if echo ${line} | grep -q  "server start complete"; then
              echo 'Server Started'
              # stop the timer..
              kill ${timerPid} > /dev/null 2>&1
            fi
        done &
    
        echo "Starting Server."
        $instanceDir/bin/startserver.sh > /dev/null 2>&1 &
    
        # wait for the timer to expire (or be killed)
        wait %sleep
    
    }
    
    stopServer
    startServer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write an awk script that can get a block that
I am trying to get file extension for a file in shell script. But
I'm trying to get the contents of a directory using shell script. My script
I'm trying to get the contents of a directory using shell script. My script
I'm trying to get the command history inside a shell script. It doesn't work
I'm trying to create a new launchagent file that will execute a shell script
I am trying to get the name of the shell executing a script. Why
I am trying to write a simple shell-script that prints out the first parameter
I am trying to write a shell script, where emails get piped to (by
I am trying to write a shell script that will search for a regular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.