From 5bf228bb0449145e8fb67c0eb6804906d369cd12 Mon Sep 17 00:00:00 2001 From: pvincent Date: Mon, 29 Apr 2024 20:43:46 +0400 Subject: [PATCH] wait_for_ping --- tools/wait_for_ping | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 tools/wait_for_ping diff --git a/tools/wait_for_ping b/tools/wait_for_ping new file mode 100755 index 0000000..b355ce4 --- /dev/null +++ b/tools/wait_for_ping @@ -0,0 +1,10 @@ +#!/bin/bash + +ping_cancelled=false # Keep track of whether the loop was cancelled, or succeeded +until ping -w1 -c1 "$1" >/dev/null 2>&1; do :; done & # The "&" backgrounds it +trap "kill $!; ping_cancelled=true" SIGINT +wait $! # Wait for the loop to exit, one way or another +trap - SIGINT # Remove the trap, now we're done with it +echo "Done pinging, cancelled=$ping_cancelled" + +