Skip to content
This repository was archived by the owner on Mar 30, 2020. It is now read-only.

Commit e2595d0

Browse files
committed
Merge pull request #14 from KrustyHack/master
Adding when-down and until-error.
2 parents db56881 + 25b81f1 commit e2595d0

3 files changed

Lines changed: 84 additions & 1 deletion

File tree

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ Trivial (ba)sh alternatives:
378378
when-up
379379
-------
380380

381-
Waits until a given host is online (determined by ping until executing a given command
381+
Waits until a given host is online (determined by ping until executing a given command)
382382

383383
Example:
384384

@@ -393,6 +393,40 @@ Alternatives:
393393

394394

395395

396+
until-error
397+
-------------
398+
399+
Repeat the specific command until it fails - run at least once
400+
always.
401+
402+
Example:
403+
404+
./until-error ssh example.com -l root -i ~/.ssh/example.com.key
405+
406+
Trivial (ba)sh alternatives:
407+
408+
* while true ; do $cmd; done
409+
* watch -n 2 $cmd
410+
411+
412+
413+
when-down
414+
-------
415+
416+
Waits until a given host is down
417+
418+
Example:
419+
420+
$ ./when-down 1.2.3.4 echo "down"
421+
Waiting for 1.2.3.4 to get down...
422+
down
423+
424+
Alternatives:
425+
426+
* `until-error ping -c 1 -W 1 1.2.3.4; echo "down"`
427+
428+
429+
396430
which-shell
397431
-----------
398432

until-error

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
#
3+
# About
4+
# -----
5+
# Repeat the command until it fails
6+
#
7+
8+
"$@"
9+
10+
#
11+
# If the status code was zero then repeat.
12+
#
13+
while [ $? -eq 0 ]; do
14+
"$@"
15+
done
16+
17+

when-down

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
#
3+
# Wait until a given host is down (determined by ping) then execute the
4+
# given command
5+
#
6+
# Usage:
7+
# ./when-down HOST COMMAND...
8+
#
9+
# Example
10+
# ./when-down 1.2.3.4 ssh 1.2.3.4
11+
#
12+
13+
14+
#
15+
# Ensure we received the correct number of arguments.
16+
#
17+
if [ $# -lt 2 ]; then
18+
echo "Usage: when-down HOST COMMAND..."
19+
exit 1
20+
fi
21+
22+
HOST=$1
23+
24+
echo "Waiting for $HOST to get down..."
25+
26+
true
27+
while [ $? -ne 1 ]; do
28+
ping -c 1 -W 1 $HOST >/dev/null
29+
done
30+
31+
shift
32+
$*

0 commit comments

Comments
 (0)