Solved

How to get the Unix machine name in a shell script?

Posted on 2011-09-26
3
421 Views
Last Modified: 2012-05-12
Hi,
I have shell (tcsh) script and I would like to get the name of the machine that I run this script and assign it to a variable.

How can I do it?

Thanks,
0
Comment
Question by:Tolgar
3 Comments
 
LVL 21

Assisted Solution

by:Papertrip
Papertrip earned 270 total points
ID: 36673379
uname -n

Open in new window


You can also do 'hostname', but that is potentially dangerous since anything you accidentally put after 'hostname' will change the hostname of your machine.

Real world example:
Old Solaris machine running some productions DB's
Instead of 'sudo -s' they ran messed up and typed 'hostname -s' and hosed the system ;)
0
 
LVL 48

Accepted Solution

by:
Tintin earned 230 total points
ID: 36686442
set variable=`uname -n`

Open in new window

0
 
LVL 4

Expert Comment

by:Anacreo
ID: 36712106
It should already be in the variables...

${HOST}
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now