Skip to content

Commit

Permalink
Avoid the same hostname in one session
Browse files Browse the repository at this point in the history
By adding a # in front of used words, genhost will not display
the same word in two subsequent runs. It is however possible to
display the same word within one run. When generating a large
number of hosts, it might be hard to notice the duplication.
This commit solves this issue by filtering the wordlist in each
iteration. The code for this is not very beautiful, since bash
arrays are essentially associative arrays.

Signed-off-by: Jonas Eriksson <zqad@acc.umu.se>
  • Loading branch information
zqad authored and elasticdog committed Sep 22, 2014
1 parent 1ff2ba8 commit b9de92b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions genhost
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ for i in $(seq $1); do
sed -i "/^${lines[r]}\$/ s/^/#/" "$wordlist"
;;
esac

# filter the word list to avoid outputting the same hostname twice in one
# session
m=0
unset lines_new
for (( j = 0 ; j < n ; j++)); do
if [ $j -ne $r ]; then
lines_new[$((m++))]=${lines[j]}
fi
done
lines=("${lines_new[@]}")
n=$m
done

exit 0

0 comments on commit b9de92b

Please sign in to comment.