Skip to main content
code formatting for commands
Source Link
muru
  • 78.4k
  • 16
  • 214
  • 320

Assuming /opt/abc/bin/stop/opt/abc/bin/stop doesn't block your script seem to work.
As muru suggested you could skip the $count$count variable and use the builtin $SECONDS$SECONDS. This would lead to code like this:

/opt/abc/bin/stop
# Wait for 10 second
sleep 10
# Number of seconds to wait
WAIT_SECONDS=300
while pgrep abc_test > /dev/null
do
    echo "server is still running. Seconds: $SECONDS"
    # Wait for one second
    sleep 1
    # Have we exceeded $WAIT_SECONDS? If so exit the loop
    if [ $SECONDS -gt $WAIT_SECONDS ]; then
        break
    fi
done

In case /opt/abc/bin/stop/opt/abc/bin/stop DOES block, just call it in the background like:
/opt/abc/bin/stop &

/opt/abc/bin/stop &

Assuming /opt/abc/bin/stop doesn't block your script seem to work.
As muru suggested you could skip the $count variable and use the builtin $SECONDS. This would lead to code like this:

/opt/abc/bin/stop
# Wait for 10 second
sleep 10
# Number of seconds to wait
WAIT_SECONDS=300
while pgrep abc_test > /dev/null
do
    echo "server is still running. Seconds: $SECONDS"
    # Wait for one second
    sleep 1
    # Have we exceeded $WAIT_SECONDS? If so exit the loop
    if [ $SECONDS -gt $WAIT_SECONDS ]; then
        break
    fi
done

In case /opt/abc/bin/stop DOES block, just call it in the background like:
/opt/abc/bin/stop &

Assuming /opt/abc/bin/stop doesn't block your script seem to work.
As muru suggested you could skip the $count variable and use the builtin $SECONDS. This would lead to code like this:

/opt/abc/bin/stop
# Wait for 10 second
sleep 10
# Number of seconds to wait
WAIT_SECONDS=300
while pgrep abc_test > /dev/null
do
    echo "server is still running. Seconds: $SECONDS"
    # Wait for one second
    sleep 1
    # Have we exceeded $WAIT_SECONDS? If so exit the loop
    if [ $SECONDS -gt $WAIT_SECONDS ]; then
        break
    fi
done

In case /opt/abc/bin/stop DOES block, just call it in the background like:

/opt/abc/bin/stop &
Source Link

Assuming /opt/abc/bin/stop doesn't block your script seem to work.
As muru suggested you could skip the $count variable and use the builtin $SECONDS. This would lead to code like this:

/opt/abc/bin/stop
# Wait for 10 second
sleep 10
# Number of seconds to wait
WAIT_SECONDS=300
while pgrep abc_test > /dev/null
do
    echo "server is still running. Seconds: $SECONDS"
    # Wait for one second
    sleep 1
    # Have we exceeded $WAIT_SECONDS? If so exit the loop
    if [ $SECONDS -gt $WAIT_SECONDS ]; then
        break
    fi
done

In case /opt/abc/bin/stop DOES block, just call it in the background like:
/opt/abc/bin/stop &