pinnacle has asked for the wisdom of the Perl Monks concerning the following question:

I am unable to ssh into *nix box, it always says: "Net::SSH: Bad host name: tic-rhel5-20-12" when I check hostname on box it says

[root@tic-rhel5-20-12 ~]# hostname tic-rhel5-20-12

CODE:

#!/usr/bin/perl use Net::SSH::Perl; use strict; my $host = "tic-rhel5-20-12"; my $user = "ssh root\@10.10.20.12"; my $passwd = "test"; my $cmd = "ls -l /root"; my $ssh = Net::SSH::Perl->new($host); my $ssh->login($user,$passwd); print "looking..."; my ($output, $error, $exit) = $ssh->cmd("$cmd"); print "Result:\n"; print $output;

Please help, Thanks!!

Replies are listed 'Best First'.
Re: Unable to ssh in linux box
by choroba (Cardinal) on May 12, 2011 at 15:00 UTC
    Try hostname -f. The domain part is missing.
      [root@tic-rhel5-20-12 ~]# hostname -f tic-rhel5-20-12

      It still gives same hostname on the box

Re: Unable to ssh in linux box
by Khen1950fx (Canon) on May 12, 2011 at 16:32 UTC
    I recently changed providers. Everything works, but the provider insists on muscling-out "localhost". The result is that when I try to use a ssh module, it comes back with "Bad Hostname". Make sure that localhost is working, or use your host's info.

      Reply to all

      I tried "uname -n" it still gives "tic-rhel5-20-12"

      localhost is working fine

      I escaped

      my $cmd = "ls \-l \/root";

      Still same error Net::SSH: Bad host name: tic-rhel5-20-12

        It works for me now, I troubleshooted myself, I changed the hostname to actual "ip address" and username to just "root" it worked for me

Re: Unable to ssh in linux box
by BradV (Sexton) on May 12, 2011 at 16:08 UTC

    Try "uname -n" to get the name. Under some OS's it will return just the hostname. On others, it will return the FQDN.

Re: Unable to ssh in linux box
by Anonymous Monk on May 12, 2011 at 16:16 UTC
    Do you need to escape the '-' ?