Skip to content

Commit

Permalink
Error out when no more available host names
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticdog committed Oct 12, 2014
1 parent b61494d commit d58f0b0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion genhost
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if [[ -z $1 ]]; then
exit 1
else
if [[ $1 == *[!0-9]* ]]; then
echo "'$1' is not a positive integer"
echo "'$1' is not a positive integer" >&2
exit 1
fi
fi
Expand All @@ -37,6 +37,11 @@ while IFS= read -r 'lines[n++]'; do :; done < <(sed '/^#/d' "$wordlist")

# output the random hostname(s)
for i in $(seq $1); do
if [[ $n -eq 0 ]]; then
echo "no more available hostnames left in file $wordlist" >&2
exit 1
fi

# pick a random available word
rand $n
echo "${lines[r]}.${domain}"
Expand Down

0 comments on commit d58f0b0

Please sign in to comment.