Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine the server name in script

Status
Not open for further replies.

davidx

Programmer
Oct 6, 2000
10
US
As a newbie to the Unix script language I'm not sure how to retrieve the server name within script. Or how to retrieve system values for use within the script. The script I'm writing for reporting system status will be run on 9 servers. I would like to include the server name in the messaging sent to operations when there is a problem.

Thanks

Dave
 
Dave,

The commands:

uname -a

and

hostname

both print the hostname. one or the other will be available.

using the korn shell or the posix shell you can get the name of the host into a variable like this

HOST=$(hostname) || HOST=$(uname -a)

The second command only gets run if th first one fails (that's the || bit)

Mike
michael.j.lacey@ntlworld.com
 
useing uname is a better way then using hostname. Some people will make a mistake and write things like:
hostname=.... witch will change your hostname.
HOST=$(uname -n) will display the name of your host and place it in $HOST

Greetings,
Wim Alsemgeest
The Netherlands
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top