Permalink
Browse files

Updated to use /bin/sh

  By dropping the fancy positional-argument extraction, and using
 `shift` we can run under dash, etc.
  • Loading branch information...
1 parent 60aa1cd commit 0da9c30b9890c05c9994720bc7ad802a42b809ff @skx committed Dec 28, 2013
Showing with 15 additions and 8 deletions.
  1. +15 −8 when-up
View
23 when-up
@@ -1,5 +1,5 @@
-#! /bin/bash
-
+#!/bin/sh
+#
# Wait until a given host is online (determined by ping) then execute the
# given command
#
@@ -8,10 +8,15 @@
#
# Example
# ./when-up 1.2.3.4 ssh 1.2.3.4
+#
+
+#
+# Ensure we received the correct number of arguments.
+#
if [ $# -lt 2 ]; then
- echo "Usage: when-up HOST COMMAND..."
- exit 1
+ echo "Usage: when-up HOST COMMAND..."
+ exit 1
fi
HOST=$1
@@ -20,9 +25,11 @@ echo "Waiting for $HOST to come online..."
false
while [ $? -ne 0 ]; do
- sleep 1
- ping -c 1 -W 1 $HOST >/dev/null
+ sleep 1
+ ping -c 1 -W 1 $HOST >/dev/null
done
-# It's up, do what we're told
-${@:2}
+# By the time we reach here the ping-command has completed successfully
+# so we can launch the command we were given - along with any arguments.
+shift
+$*

0 comments on commit 0da9c30

Please sign in to comment.