On 08/26/2019 03:40 PM, Kairui Song wrote:
On Mon, Aug 26, 2019 at 1:56 PM Pingfan Liu piliu@redhat.com wrote:
'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 }')If there are multiple alias, this will only catch the first one? eg. in my /etc/hosts there is: 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
and: # echo 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 | awk '{ print $3 }' localhost.localdomain
You are right, I will fix it in V2.
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 )
A redundant space?
OK, I can strip it in V2.
Thanks, Pingfan
local nodename=$1
- hostnames="$hostnames $shortnames"
hostnames="$hostnames $shortnames $aliasname"
for name in ${hostnames}; do if [ "$name" == "$nodename" ]; then
-- 2.7.5