June Tate-Gans | 8496433 | 2018-12-20 14:14:25 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
2 | |||||
3 | random_word() | ||||
4 | { | ||||
5 | local wordlist=$1; shift | ||||
6 | local max=$(wc -l $wordlist |awk '{ print $1 }') | ||||
7 | local line=$(($RANDOM % $max + 1)) | ||||
8 | |||||
9 | head -n $line $wordlist |tail -n 1 | ||||
10 | } | ||||
11 | |||||
12 | generate_hostname() | ||||
13 | { | ||||
14 | local adj=$(random_word /tmp/adjectives.txt) | ||||
15 | local noun=$(random_word /tmp/nouns.txt) | ||||
16 | |||||
17 | echo "${adj}-${noun}" | ||||
18 | } | ||||
19 | |||||
20 | hostname=$(generate_hostname) | ||||
21 | echo $hostname >/etc/hostname | ||||
22 | /usr/bin/hostnamectl set-hostname $hostname |