Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a pretty easy problem I'm trying to resolve here. I'm constantly running the (host) command on domains, to get their IPs, then (host) again on those IPs to get their PTRs, then I'm SSHing to that server represented in the PTR:

[root@box ~]$ host DomainIWant.com
DomainIWant.com has address 123.123.123.123

[root@box ~]$ host 123.123.123.123
123.123.123.123.in-addr.arpa domain name pointer vps2010.DomainIWantHosts.com

[root@box ~]$ ssh vps2010.DomainIWantHosts.com

Simple enough right? It's just tedious doing this over and over, so as with everything Linux I want to speed it up by automating it:

[root@box ~]$ host DomainIWant.com | awk '{print $4}' | xargs host | awk '{print $5}' | xargs ssh -tt

The problem that I'm having is when I call ssh via xargs, I do get SSH'd into the remote server but with the error [tcgetattr: Invalid argument]. I'm sitting at the remote server's shell but when I try to run any command it just hangs and eventually I have to Ctrl-C to break out of it.

If I don't tack on the (ssh -tt) then I get a [Pseudo-terminal will not be allocated because stdin is not a terminal] error. This seems like such a simply problem so I'm hoping someone more familiar with ssh via xargs can let me know if it's even possible.

share|improve this question
    
Are you getting into the server using ssh? If so, this should not be the problem of the command you presented above. –  Khaled Nov 27 '10 at 15:14
    
Yes I'm SSHing into a box inside a network, then using that box to jump to other ones on the same network. Using the above commands both lead to the 2nd server I'm connecting to not allowing me to type in any input. –  JacobN Dec 2 '10 at 3:20

1 Answer 1

up vote 4 down vote accepted

If you're using a shell that supports backticks- or $()-style command substitution (most shells do), then in your case, you can avoid using xargs entirely, like this:

ssh $(host -t PTR $(host -t A DomainIWant.com | awk '{print $4}') | awk '{print $5}')

(I added the -t flags to the host commands, to ensure they only emit 1 line of output.)

share|improve this answer
    
Thanks! This worked just as I wanted, nice to see I can bypass xargs all together. That's why I love Linux always more than one way to accomplish something. –  JacobN Dec 2 '10 at 3:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.