LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   test for name of localhost in script (https://www.linuxquestions.org/questions/linux-newbie-8/test-for-name-of-localhost-in-script-412335/)

Lotharster 02-06-2006 03:08 PM

test for name of localhost in script
 
I want to write a script that tests during execution on which machine it is running. I'd like to test for the name of the localhost, something like
Code:

if [ $localhost = fs01phy ]; then echo jepp ; fi
But I don't know how to get the name of the localhost. There is no environment variable called $LOCALHOST or the like.

Thanks,
Lotharster

satinet 02-06-2006 03:23 PM

there's always hostname or uname -a

localhost=`hostname`

if test $localhost = whatever
then
something
else
something
fi

pljvaldez 02-06-2006 03:24 PM

Try hostname -f for fully qualified domain or hostname -s for just the hostname cut off at the first dot. You can assign it a variable in your script if you want, i.e. LOCALHOST=`hostname -s`. Note that those are back quotes (the ~ key)

Lotharster 02-06-2006 03:38 PM

thanks for your quick replies!

Lotharster


All times are GMT -5. The time now is 04:24 PM.