Solved

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

Posted on 2011-09-26
3
430 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

776 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