LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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: 18
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 14.2
Posts: 1,491

Rep: Reputation: 50
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
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
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: 18
Smile

thanks for your quick replies!

Lotharster
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:51 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration