wait_for_8080.bash: adds third argument: a program to execute

Signed-off-by: Jed Reynolds <jreynolds@candelatech.com>
This commit is contained in:
Jed Reynolds
2022-06-15 12:10:32 -07:00
committed by shivam
parent 2961fc749e
commit 2aa549cefb

View File

@@ -3,9 +3,9 @@
# wait_for_8080.bash # wait_for_8080.bash
# #
# Use as a trigger for starting a script that connects to the GUI # Use as a trigger for starting a script that connects to the GUI
# Usage: ./wait_for_8080.bash SECONDS URL # Usage: ./wait_for_8080.bash SECONDS URL NEXT_PROGRAM
# Example: # Example:
# ./wait_for_8080.bash $((60 * 2)) http://localhost:8080/ # ./wait_for_8080.bash $((60 * 2)) http://localhost:8080/ "/home/lanforge/scripts/scenario.py"
# The URL must be exact and include the http port in the URL. # The URL must be exact and include the http port in the URL.
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- # ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
# set -vux # set -vux
@@ -13,12 +13,12 @@
DEFAULT_WAIT_SECS=$(( 60 * 5 )) # 5 minutes DEFAULT_WAIT_SECS=$(( 60 * 5 )) # 5 minutes
WAIT_SECS=${1:-$DEFAULT_WAIT_SECS} WAIT_SECS=${1:-$DEFAULT_WAIT_SECS}
URL=${2:-http://localhost:8080/} URL=${2:-http://localhost:8080/}
NEXT_PROGRAM=${3:-}
if [[ x$WAIT_SECS = x ]] || (( $WAIT_SECS < 1 )); then if [[ x$WAIT_SECS = x ]] || (( $WAIT_SECS < 1 )); then
echo "Usage: $0 SECONDS URL" echo "Usage: $0 SECONDS URL NEXT_PROGRAM"
echo "The URL must be exact and include the http port in the URL." echo "The URL must be exact and include the http port in the URL."
echo "Example:" echo "Example:"
echo " $0 600 http://localhost:8080/" echo " $0 600 http://localhost:8080/ '/usr/bin/xterm -e top'"
exit 1 exit 1
fi fi
@@ -29,7 +29,10 @@ while (( $SECS_WAITED <= $WAIT_SECS )); do
curl -o /dev/null -sq $URL curl -o /dev/null -sq $URL
if (( $? == 0 )); then if (( $? == 0 )); then
echo "Connected to $URL in $SECS_WAITED" | tee >( logger -t lfclient) echo "Connected to $URL in $SECS_WAITED" | tee >( logger -t lfclient)
exit 0 if [[ x$NEXT_PROGRAM == x ]]; then
exit 0
fi
exec $NEXT_PROGRAM
fi fi
sleep 1 sleep 1
SECS_WAITED=$(( SECS_WAITED+=1 )) SECS_WAITED=$(( SECS_WAITED+=1 ))