usr_bin/random-hostname: Fix a couple of shellcheck warnings
authorDarshaka Pathirana <dpat@syn-net.org>
Fri, 5 Feb 2021 13:56:00 +0000 (14:56 +0100)
committerDarshaka Pathirana <dpat@syn-net.org>
Fri, 3 Dec 2021 11:54:54 +0000 (12:54 +0100)
commit2980f79718344ea7bbb6093beb9b6bac49b5566d
tree3b655e99fadea0ae567dfb8845c85d6d43f0188e
parent6f0b926f0885ead82fa4e43856f85825c245241e
usr_bin/random-hostname: Fix a couple of shellcheck warnings

- Ignore SC2034: hostnames appears unused. Verify use (or export if used externally).

While at it I rewrote the way how the random hostname is retrieved:

First find the line number 3 lines after the line which starts with "# EOF"
This is the line where the list of hostnames start.
This makes the script a bit more robust and avoids the hard coded start
line calculation ("num=$(( $num - 16 ))").

Then list all lines from there by excluding all empty commented out
lines and the last line (which start with "'").
Use "sort -R" to randomly sort the list and from there take the last line.

That way the confusing "randline" variable calculation is avoided.
usr_bin/random-hostname