Why is hostname and $HOSTNAME different?

Wade Smart wadesmart at gmail.com
Wed May 11 16:48:36 UTC 2022


etc/hostname
Change it there.
-- 
Registered Linux User: #480675
Registered Linux Machine: #408606
Linux since June 2005

On Wed, May 11, 2022 at 11:32 AM Bo Berglund <bo.berglund at gmail.com> wrote:
>
> This is in Ubuntu Server 20.04.4 LTS
>
> I have some scripts that use the hostname to switch some paths when running.
> It has been OK for a long time but now after I did a router f/w upgrade my
> scripts fail.
>
> And I think this is the cause of it all:
>
> $ hostname
> ubuntusrv
> $ echo $HOSTNAME
> ubuntuserv
>
> Notice the difference in the return from these commands, which I thouight would
> be identical.
>
> Inside the scripts I use this construct:
>
> if [ "$HOSTNAME" == "ubuntuserv" ]; then
>   URLFILE="$HOME/www/url_strm.txt"   #Main web server file path
> else
>   URLFILE="$HOME/lan/url_strm.txt"   #Secondary device file path
> fi
>
> And it has worked fine for ages, but failed today after the router update.
>
> Can the DHCP server in the router affect the hostname of a device which is using
> it to get its IP address?
> I had to go over and re-enter the DHCP reservations after a f/w update on the
> router forced me to reset to factory and re-enter the complete config by hand.
>
> If so what is the correct way in a script to get the *real* hostname which is
> shown on the command line in terminal?
>
>
> --
> Bo Berglund
> Developer in Sweden
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users




More information about the ubuntu-users mailing list