Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-09-26
3
Medium Priority
?
484 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 21

Assisted Solution

by:Papertrip
Papertrip earned 1080 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 920 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

Hire Technology Freelancers with Gigs

Work with 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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

604 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