You are not logged in.

#1 2023-04-06 12:53:40

orel
Member
Registered: 2023-04-06
Posts: 3

fqdn without hostname

Hello,

If the hostname command is not installed, what would be the best way (understand: usable with a basic installation) to have an alternative to the hostname --fqdn command to get the fully qualifed domain name of localhost?

The hostnamectl command does not provide fqdn and systemd-resolved may not be available if we do not use systemd to configure the network…

Offline

#2 2023-04-06 14:33:19

seth
Member
Registered: 2012-09-03
Posts: 60,799

Re: fqdn without hostname

"hostname --fqdn" effectively just prints the first domain from "getent hosts" - it doesn't even have to be a fqdn.
How you get that (getent is part of glibc) depends on what you consider a "basic installation", but bash parameter expansion can do that.

Maybe you explain what you actually want to achieve here?

Online

#3 2023-04-06 16:11:09

orel
Member
Registered: 2023-04-06
Posts: 3

Re: fqdn without hostname

I ask this question because I encountered a bug in the use of liquiprompt that attempts to retrieve the host name via the hostname command.

The maintainer handled the initial issue by fetching the values from the environment variables provided by zsh or bash, but the issue still arises for one of the features of this prompt that displays fqdn as hostname.(https://github.com/nojhan/liquidprompt/ … 2278-L2286)

That's why I'm trying to find a solution that can be used regardless of the network configuration and without the hostname command, to find the FQDN of the host smile

Offline

#4 2023-04-06 19:20:16

seth
Member
Registered: 2012-09-03
Posts: 60,799

Re: fqdn without hostname

getent hosts | awk 'NR==1{print $2}'
getent hosts | awk '{print $2;exit}'

awk is a dependency of pacman, so that's basic enough, I guess?

Online

#5 2023-04-06 19:38:29

orel
Member
Registered: 2023-04-06
Posts: 3

Re: fqdn without hostname

something like this should do the trick:

getent hosts | awk /"${HOSTNAME:-${HOST-}}"./'{print $2}'

thanks for the answers smile

Offline

#6 2023-04-06 19:43:36

seth
Member
Registered: 2012-09-03
Posts: 60,799

Re: fqdn without hostname

As mentioned, hostname doesn't actually care about /etc/hostname - no idea how relevant that is w/ liquiprompt.

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Online

Board footer

Powered by FluxBB