LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-06-2006, 03:08 PM   #1
Lotharster
Member
 
Registered: Nov 2005
Posts: 144

Rep: Reputation: 15
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
 
Old 02-06-2006, 03:23 PM   #2
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 11, Sabayon 3.1
Posts: 1,464

Rep: Reputation: 46
there's always hostname or uname -a

localhost=`hostname`

if test $localhost = whatever
then
something
else
something
fi
 
Old 02-06-2006, 03:24 PM   #3
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
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)
 
Old 02-06-2006, 03:38 PM   #4
Lotharster
Member
 
Registered: Nov 2005
Posts: 144

Original Poster
Rep: Reputation: 15
Smile

thanks for your quick replies!

Lotharster
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script 'test' question linmix Programming 5 11-29-2005 11:49 AM
how to grep within a script, and test result? bobbyr Programming 4 01-13-2004 12:11 PM
Only test.cgi script works? lonny Programming 1 12-09-2003 08:38 PM
bash script test file operators... bulliver Programming 3 10-17-2003 12:06 PM
benchmark test bash script PTBmilo Programming 3 02-14-2003 04:37 PM


All times are GMT -5. The time now is 11:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration