'hostname -A' can not get the alias, meanwhile 'hostname -a' is deprecated. So we should do it by ourselves.
The parsing is based on the format of /etc/hosts, i.e. IP_address canonical_hostname [aliases...]
Signed-off-by: Pingfan Liu piliu@redhat.com --- dracut-module-setup.sh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 3fa696d..4187554 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -689,12 +689,33 @@ kdump_check_iscsi_targets () { } }
+# hostname -a is deprecated, do it by ourselves +get_alias() { + local ips + local entry + local _alias + local alias_set + + ips=$(hostname -I) + for ip in $ips + do + entry=$(grep $ip /etc/hosts) + if [ $? -eq 0 ]; then + _alias=$(echo $entry | awk '{ print $3 }') + alias_set="$alias_set $_alias" + fi + done + + echo $alias_set +} + is_localhost() { local hostnames=$(hostname -A) local shortnames=$(hostname -A -s) + local aliasname=$(get_alias ) local nodename=$1
- hostnames="$hostnames $shortnames" + hostnames="$hostnames $shortnames $aliasname"
for name in ${hostnames}; do if [ "$name" == "$nodename" ]; then