finding the hostname of a remote system


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding the hostname of a remote system
# 1  
Old 03-29-2012
finding the hostname of a remote system

I know the ipaddress of a remote machine and would like to know its hostname

I used the nslookup command but... is there an easier way of doing it... just like hostname command.
When i give this command i get the following
Code:
nslookup 10.2.47.36
Server:      10.233.04.31
Address:    10.233.04.31$35

13.29.28.10.in-addr.prap            name = cinderella.apm42.local.

Now I'm only interested in the word cinderella over here so i used the following

Code:
nslookup 10.2.47.36 | grep name

I just want to get the word cinderella and assign it to a variable how do i do it
# 2  
Old 03-29-2012
Quote:
Originally Posted by ramky79
I know the ipaddress of a remote machine and would like to know its hostname

I used the nslookup command but... is there an easier way of doing it... just like hostname command.
When i give this command i get the following
Code:
nslookup 10.2.47.36
Server:      10.233.04.31
Address:    10.233.04.31$35

13.29.28.10.in-addr.prap            name = cinderella.apm42.local.

Now I'm only interested in the word cinderella over here so i used the following


Code:
nslookup 10.2.47.36 | grep name

I just want to get the word cinderella and assign it to a variable how do i do it

only an awk away Smilie
Code:
nslookup 10.2.47.36 | grep name | awk -F= '{print $NF}'

# 3  
Old 03-29-2012
Code:
yourhost=$(nslookup 10.2.47.36 | awk '/name/ {split ($4,elems,"."); print elems[1]}')


Last edited by CarloM; 03-29-2012 at 12:12 PM.. Reason: variable assignment
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk remote multiple hosts print remote hostname and output

Hi all, i'm trying to gether multiple pattern on remote hosts, and trying to print hostname and the pattern, ssh remoteserver1 -C 'hostname 2>&1;cat /var/log/server1.log | awk -F ";" '"'"'{ print " "$2" "$5}'"'"'| sort | uniq -c | sort -g -r ' The output is the following, remoteserver1 ... (8 Replies)
Discussion started by: charli1
8 Replies

2. Emergency UNIX and Linux Support

HP UX - ILO Console hostname different than Machine Hostname...

Hi All, So we added a new HP-UX 11.31 machine. Copied OS via Ignite-UX (DVD)over from this machine called machine_a. It was supposed to be named machine_c. And it is when you log in...however when I'm in the ILO console before logging in, it says: It should say: What gives? And how do... (4 Replies)
Discussion started by: zixzix01
4 Replies

3. Solaris

how to login with ssh to remote system with out applying the remote root/usr password

how to login with ssh to remote system with out applying the remote root/user password with rlogin we can ujse .rhosts file but with ssh howits possible plz guide (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

4. Shell Programming and Scripting

Pulling remote hostname into variable

I'm trying to write a shell script using bash that connects to a remote server, runs a command that generates a file, pulls the file over, then renames it with the hostname of the remote server and a an extension. So far, I'm able to everything but pull the hostname of the remote server into a... (2 Replies)
Discussion started by: hobbes80
2 Replies

5. UNIX for Advanced & Expert Users

rsh not finding .profie in the remote server; please help

while using the rsh command to execute script S1 in the remote server it is not using the .profile in remote server. The script S1 which is using sqlplus is not able to set up the ORACLE environment which is defined in .profile Thanks in advance.... (3 Replies)
Discussion started by: jaiankur
3 Replies

6. UNIX for Dummies Questions & Answers

Hostname - System Name

Hello Can anyone tell me the difference between a hostname and system name in UNIX?. Rgds D (3 Replies)
Discussion started by: deedaz
3 Replies

7. UNIX for Dummies Questions & Answers

how to mount a file system of a remote machine to local file system

Hi friends, In my case, there are serveral PCs running Linux in a LAN. I would like to to mount the directory /A_river of machine-A to the file system of another machine machine-B so that I can access files in that directory. I do not know how to do this. The situation is complicated by... (2 Replies)
Discussion started by: cy163
2 Replies

8. UNIX for Dummies Questions & Answers

Solaris - unknown hostname - how can I change hostname?

Hello, I am new to Solaris. I am using stand alone Solaris 10.0 for test/study purpose and connecting to internet via an ADSL modem which has DHCP server. My Solaris is working on VMWare within winXP. My WinXP and Solaris connects to internet by the same ADSL modem via its DHCP at the same... (1 Reply)
Discussion started by: XNOR
1 Replies

9. UNIX for Dummies Questions & Answers

Finding system info

Can someone tell me the command to display the info about the CPU? I need the CPI id.. of my SUN box. Solaris 8. It's some totally un-intuitive command, and i can't recall it. tnx. (3 Replies)
Discussion started by: ireeneek
3 Replies

10. UNIX for Dummies Questions & Answers

Finding out available C++ compilers on my system

How can I find out what C++ compilers are available on my system? Thanks in advance (7 Replies)
Discussion started by: HelpMeIAmLost
7 Replies
Login or Register to Ask a Question