Solved

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

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Removing DES and 3DES ciphers in linux RedHat 6.8 38 95
linux pull logs and export FTP 4 59
route 2 traffic streams on single NIC 6 35
Adding more CPU cores to a Linux VM 5 60
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

912 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

22 Experts available now in Live!

Get 1:1 Help Now