X-Git-Url: http://git.grml.org/?p=grml-scripts.git;a=blobdiff_plain;f=usr_bin%2Frandom-hostname;fp=usr_bin%2Frandom-hostname;h=7386abb04a06da090ee932707c598492838f8745;hp=b52352380c7538d2a94def70d008348cd0be41da;hb=54e2502b301f2220e49e619b263be0e015d807cc;hpb=29bfc533ade39978f73afaecf01062151e43e267 diff --git a/usr_bin/random-hostname b/usr_bin/random-hostname index b523523..7386abb 100755 --- a/usr_bin/random-hostname +++ b/usr_bin/random-hostname @@ -5,13 +5,13 @@ # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. ################################################################################ -num=$(wc -l $0) -num=${num%% $0} -num=$(( $num - 16 )) -randline=$(($(date +%Y%M%S) * $$ % $num)) -hostname=$(tail -n $randline "$0" | head -1 | grep -v "'" | grep -v '^#' | grep -v '^$') +hostname_start=$(grep -n "^# EOF" "$0") +hostname_start=${hostname_start%%:#*} +hostname_start=$(( hostname_start + 3 )) +hostname=$(tail -n +$hostname_start "$0" | grep -v "'" | grep -v '^#' | grep -v '^$' | sort -R | tail -1) [ -n "$hostname" ] && echo "$hostname" || echo "grml" -# EOF - line 15; now the hostnames: +# EOF - now the hostnames: +# shellcheck disable=SC2034 hostnames=' 23 42