Getting hostname using ssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting hostname using ssh
# 8  
Old 06-30-2011
Just curious: why don't you use the hostname used for the scp connection? Is it different from the machine's hostname output?

Code:
scp -p "$host:/tmp/$host.html.gz" ...

Ooops, I just saw that Scott had already asked the same question Smilie

Last edited by radoulov; 06-30-2011 at 05:12 PM..
# 9  
Old 06-30-2011
I dont want to redirect the name to a local file, otherwise I would've done it.

How can I save the output of a command to a local variable in my script, not to a local file?

---------- Post updated at 12:29 PM ---------- Previous update was at 12:28 PM ----------

Quote:
Originally Posted by scottn
What are you trying to do? You already know the hostname... you use it to connect to the host.

Code:
scp -p $host:/tmp/$host.html.gz ...


my host is server1
my hostname includes the domain.... server1.domain.com
# 10  
Old 06-30-2011
Quote:
Originally Posted by eponcedeleonc
I dont want to redirect the name to a local file, otherwise I would've done it.

How can I save the output of a command to a local variable in my script, not to a local file?
Same way you do it any other time.

Code:
VAR=$(ssh username@host 'cat /tmp/$(hostname).gz')

I don't think this will work for scp, because I see no way to make it print the retrieved file into standard output. again, scp is not a shell.
# 11  
Old 06-30-2011
my host is server1
my hostname includes the domain.... server1.domain.co
# 12  
Old 06-30-2011
I understand, and what's the problem with the solution(s) provided by Corona688?
# 13  
Old 06-30-2011
Then, just: scp $host:/tmp/$host.*.whatever ...

There's surely only one file on each host you want that matches that?
# 14  
Old 06-30-2011
yes of course, that is the workaround, but what if for some reason, the hostname does not come out with the domain name...then the script will fail!! Smilie

---------- Post updated at 12:40 PM ---------- Previous update was at 12:38 PM ----------

that is why i want to store the vale of the command "hostname" of the remote server on my script, because that way I know for sure that the file is named with that same name. does that makes sense?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Get ip of client, not hostname

Hello i'm trying to get the ip of a telnet session. With who -u I get the hostname of the user connecting to my server, because it checks the reverse DNS. But I only want the ip. Versions: HP-UX HP Release B.11.31 Who command: Hewlett-Packard Company - 4 - HP-UX 11i Version... (2 Replies)
Discussion started by: boltpower
2 Replies

2. UNIX for Advanced & Expert Users

Hostname -f hostname: Unknown host

deleted (0 Replies)
Discussion started by: hce
0 Replies

3. AIX

Hostname for each lpar

Hi Gurus, Can a AIX server with 4 LPARs, each having it's own hostname on the same physical host. Is this possible? Thanks, S (2 Replies)
Discussion started by: svajhala
2 Replies

4. UNIX for Advanced & Expert Users

$HOSTNAME empty while invoking script using SSH

Hi, I am unable to get $HOSTNAME value in a remote script when executed through SSH. Also the scripts hangs and doesnt return to the calling environment. For instance command - ssh user1@box2 "cd /var/home/bin ; ./generateScript.sh" Can any one plese throw light on the issue and... (5 Replies)
Discussion started by: mihirvora16
5 Replies

5. 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

6. Solaris

Changed hostname to -a

I was trying to execute the following command ifConfig -a and after a while my hostname changed to -a I checked /etc/hosts and /etc/nodename all seems to be correct. 1. How my hostname changed to -a ? (What i could have done wrong) 2. if you type hostname where does solaris read... (1 Reply)
Discussion started by: 2sb
1 Replies

7. 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

8. UNIX for Advanced & Expert Users

Change of Hostname

Dear All. I will like to know beside the following command "hostname hostname" what other command that can change the hostname of the Unix. Thanks. (4 Replies)
Discussion started by: gelbvonn
4 Replies

9. IP Networking

looking up hostname

Using Solaris 8 (or WINXP). I am trying to look up a specific DNS hostname, but I don't know which DNS server houses that entry. How can I find the hostname? nslookup gives me the following: C:\>nslookup hostname Server: dnsserver Address: x.x.x.x *** dnsserver can't find hostname:... (2 Replies)
Discussion started by: dangral
2 Replies

10. UNIX for Dummies Questions & Answers

Hostname

Hello, I am installing redhat linux 6.2 on an intel based system. Whether i want to know any naming conventions should i follow. ie Any convention to follow to name a linux machine(To give hostname). Simillarly for domain name also. Please suggest in this regard (1 Reply)
Discussion started by: bache_gowda
1 Replies
Login or Register to Ask a Question