Duncan Ferguson
2007-Dec-19 11:34 UTC
$HOME/.ssh/config and host/hostname resolution how-to?
Hiya, What is the easiest way of looking up a hostname to see if it exists, taking into account the .ssh/config file? If i have an entry in my file host host1 hostname server.domain.name then usual OS calls won't recognise the 'alias' host1. So, i need to make a call via ssh somehow to check if the name resolves without actually initiating a full blown 'expensive' connection to it, such as using 'ssh host1 true' or something (which also relies on 'true' being on the path, or always being installed in the same place if the path is provided - neither of which can be guaranteed). I tried ssh-keyscan, but this ignores the config file (probably correctly), so what is the more appropriate way to perform the name validation? I have tried 'ssh -n host1' which seems to work - would this be the best option? I am using: OpenSSH_4.6p1 Debian-5build1, OpenSSL 0.9.8e 23 Feb 2007 on Etch in this instance, but the method will need to be portable. Thanks Duncs
Darren Tucker
2007-Dec-19 20:40 UTC
$HOME/.ssh/config and host/hostname resolution how-to?
Duncan Ferguson wrote:> Hiya, > > What is the easiest way of looking up a hostname to see if it exists, > taking into account the .ssh/config file? > > If i have an entry in my file > > host host1 > hostname server.domain.name > > then usual OS calls won't recognise the 'alias' host1. So, i need to > make a call via ssh somehow to check if the name resolves without > actually initiating a full blown 'expensive' connection to it, such > as using 'ssh host1 true' or something (which also relies on 'true' > being on the path, or always being installed in the same place if the > path is provided - neither of which can be guaranteed). > > I tried ssh-keyscan, but this ignores the config file (probably > correctly), so what is the more appropriate way to perform the name > validation? I have tried 'ssh -n host1' which seems to work - would > this be the best option?I'm not quite sure what you're trying to achieve, could you give an example? Depending on what you want, there's a couple of options. If you just want to return quickly if the host is down, you can set the ConnectTimeout to a lowish value. If you want to do something more complicated, (eg fail if your dial-on-demand link is down or similar) you could use a ProxyCommand and implement whatever logic you want in a shell script (that finishes by exec'ing netcat). -- Darren Tucker (dtucker at zip.com.au) GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69 Good judgement comes with experience. Unfortunately, the experience usually comes from bad judgement.
On Dec 19, 2007 11:34 AM, Duncan Ferguson <duncan_j_ferguson at yahoo.co.uk> wrote:> What is the easiest way of looking up a hostname to see if it exists, > taking into account the .ssh/config file?It sounds to me like you want to use ssh to parse ~/.ssh/config for you. To avoid any overhead, you could simply parse it yourself. Hamish