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

Greeting Monks!

I'm having a problem with the above, on one server out of three. That server is running mac osx 10.7.5. The local server is mac osx 10.6.8

I can manually from the command line both ssh, and scp a file.

On the remote server, I've reviewed permissions, removed and reinstated the keys etc. etc.

Any and all help appreciated!

Thanks!

These are the outputs from the ssh and scp.

Uncaught exception from user code: SSHAuthenticationError Login timed out. The input stream curre +ntly has the contents bellow: Last login: Wed Oct 7 13:10:19 2015 fr +om xxxx-idx-dev1.xxxx.xxxxxx.com xxxx-idx-dev3:~ user$ at /System/Library/Perl/Extras/5.10.0/Expect.pm + line 828. at /Library/Perl/5.10.0/Net/SSH/Expect.pm line 209. Net::SSH::Expect::__ANON__('ARRAY(0x100eb2730)') called at /Sy +stem/Library/Perl/Extras/5.10.0/Expect.pm line 828 Expect::_multi_expect(1, 'ARRAY(0x100eb2a60)', 'ARRAY(0x100eb2 +b68)') called at /System/Library/Perl/Extras/5.10.0/Expect.pm line 56 +5 Expect::expect('Expect=GLOB(0x100eb25c8)', 1, 'ARRAY(0x100eb2c +a0)', 'ARRAY(0x100eb2e18)', 'ARRAY(0x100eb20e8)', 'ARRAY(0x100e7d548) +', 'ARRAY(0x100eb26b8)') called at /Library/Perl/5.10.0/Net/SSH/Expec +t.pm line 580 </p> <p> Net::SSH::Expect::_sec_expect('Net::SSH::Expect=HASH(0x100e7d4 +a0)', 1, 'ARRAY(0x100eb2ca0)', 'ARRAY(0x100eb2e18)', 'ARRAY(0x100eb20 +e8)', 'ARRAY(0x100e7d548)', 'ARRAY(0x100eb26b8)') called at /Library/ +Perl/5.10.0/Net/SSH/Expect.pm line 213 </p> <p> Net::SSH::Expect::login('Net::SSH::Expect=HASH(0x100e7d4a0)') + called at ./deploy_cluster.pl line 200 main::ssh_login('xxxx-idx-dev3.xxxx.xxxxxx.com', 'user', 'pass +word') called at ./deploy_cluster.pl line 154 </p> <p> main::copy_exist_to_old_all_servers('ARRAY(0x100e7d440)', ' +ARRAY(0x100eaa830)') called at ./deploy_cluster.pl line 53 </p> <p> Uncaught exception from user code: Problem performing scp: Executing: program /usr/bin/ssh host x +xxx-idx-dev3.xxxx.xxxx.com, user user, command scp -v -t /Users/user/ +Project/scripts/perl_scripts/xxxx_flush_cache_mbr.pl.new OpenSSH_5.2p1, OpenSSL 0.9.8y 5 Feb 2013 Sending file modes: C0755 13728 xxxx_flush_cache_mbr.pl Sink: C0755 13728 xxxx_flush_cache_mbr.pl at ./deploy_cluster.pl line 86. at /Library/Perl/5.10.0/Net/SCP/Expect.pm line 224.
Net::SCP::Expect::scp('Net::SCP::Expect=HASH(0x100eaa9e0)', '/Users/us +er/cvs/xxxx/Project/xxxx/xxxx/rest_...', '/Users/user/Project/scripts +/perl_scripts/xxxx_...') called at ./deploy_cluster.pl line 86 </p> <p> main::scp_to_remote_new_all_servers('ARRAY(0x100e7d488)', ' +ARRAY(0x100eaa878)') called at ./deploy_cluster.pl line 55

Replies are listed 'Best First'.
Re: net::ssh::expect net::scp::expect problem
by atcroft (Abbot) on Oct 07, 2015 at 18:47 UTC

    I have used the Net::SSH::Expect module seceral times in work-related projects. In your output (side tip: wrap it in <code></code> tags for readability), I see in the message (for Net::SSH::Expect) "SSHAuthenticationError Login timed out." I would begin by enabling logging by adding the following to the Net::SSH::Expect->new() call (where $outfile is a file location the script can write to):

    log_file => $outfile, exp_debug => 1, exp_internal => 1,
    Next, I would check that the prompt you expect to see for a successful login matches those checked for by the modules, and if necessary you may need to specify the prompt to expect, or alter the method you are using (depending on the way you are doing so in your code).

    Hope that helps.

Re: net::ssh::expect net::scp::expect problem
by shadowsong (Pilgrim) on Oct 07, 2015 at 22:22 UTC

    Hi bigswifty00000

    Without seeing the code to carry out the scp it's difficult to diagnose why the error you've displayed has occurred.

    Re: Uncaught exception from user code: SSHAuthenticationError Login timed out it appears you've timed out before a successful login...

    On the server that you're attempting to connect to; what is the LoginGraceTime field set to in your sshd_config file? (It might be a quick fix to simply increase this value, but I wouldn't go that route until we know for sure you can indeed perform a simple user/password authentication connection).

    Are you able to achieve a basic login using something like this?

    #!/usr/bin/perl use strict; use warnings; use Net::SSH::Expect; # create an SSH connection object with user,password auth my $ssh_conn = Net::SSH::Expect->new( host => '192.168.0.4', # server ip user => 'john', # user password => 'password123', # password raw_pty => 1 ); # use the SSH connection object to attempt a logon to our # SSH server using the local SSH client my $login_session = $ssh_conn->login(); die "Login attempt failed. Output: $login_session\n" if $login_session + !~ /Last login/; # arrival here signifies a successful login print "You are now logged in!\n"; # close the SSH connection $ssh_conn->close(); __END__
Re: net::ssh::expect net::scp::expect problem
by salva (Canon) on Oct 08, 2015 at 09:17 UTC
    Without seeing the source code is hard to tell what could be going wrong.

    Anyway, Net::SSH::Expect is quite unreliable because of the way it works internally. My (biased) advice, is to use Net::OpenSSH instead or, as it seems you are actually handling a cluster, Net::OpenSSH::Parallel.

Re: net::ssh::expect net::scp::expect problem
by bigswifty00000 (Beadle) on Oct 08, 2015 at 15:42 UTC
    Thanks for all the great suggestions! As requested, here is the relevant code (after some of the suggestions + implemented) and the output. It appears that the pattern match isn't working, although I'm trying t +o match anything, and again this is working on 2 other servers. It also appears as if it's asking for authentication info, yet if i ma +nually ssh it connects without user/password. Thanks again for the help!
    sub ssh_login { my ( $remote_server, $username, $password ) = @_; my $ssh = Net::SSH::Expect->new( host => $remote_server, password => $password, user => $username, raw_pty => 0, #no_terminal => 1, #port => $port, timeout=>10, #terminator=>"\r\n", log_file => '/tmp/test_ssh.log', exp_debug =>1, exp_internal =>1, ); # 2) logon to the SSH server using those credentials. # test the login output to make sure we had success my $login_output = $ssh->login(); if ( $login_output !~ /.*/ ) { #$logger->error("$0:Login has failed. Login output was $login_ +output"); print "$0:Login has failed. Login output was $login_output" . +"\n"; } $ssh->exec("stty raw -echo"); return $ssh; }
    Spawned 'ssh -e none user@****-idx-dev3.****.****.com' spawn id(5) Pid: 3237 Tty: /dev/ttys007 at /System/Library/Perl/Extras/5.10.0/Expect.pm line 181. Expect::spawn('Expect=GLOB(0x100eba4c0)', 'ssh -e none user@* +***-idx-dev3.****.****.com') called at /Library/Perl/5.10.0/Net/SSH/E +xpect.pm line 132 Net::SSH::Expect::run_ssh('Net::SSH::Expect=HASH(0x100e71bb0)' +) called at /Library/Perl/5.10.0/Net/SSH/Expect.pm line 195 Net::SSH::Expect::login('Net::SSH::Expect=HASH(0x100e71bb0)') +called at ./deploy_cluster.pl line 235 main::ssh_login('****-idx-dev3.****.****.com', 'user', 'passwo +rd') called at ./deploy_cluster.pl line 187 main::copy_exist_to_old_all_servers('ARRAY(0x100e70ef0)', 'ARR +AY(0x100e71448)') called at ./deploy_cluster.pl line 67 Starting EXPECT pattern matching... at /System/Library/Perl/Extras/5.10.0/Expect.pm line 561. Expect::expect('Expect=GLOB(0x100eba4c0)', 10, 'ARRAY(0x100eba +7a8)', 'ARRAY(0x100eb5be8)', 'ARRAY(0x100e71cd0)', 'ARRAY(0x100eb5bd0 +)', 'ARRAY(0x100eba628)') called at /Library/Perl/5.10.0/Net/SSH/Expe +ct.pm line 580 Net::SSH::Expect::_sec_expect('Net::SSH::Expect=HASH(0x100e71b +b0)', 10, 'ARRAY(0x100eba7a8)', 'ARRAY(0x100eb5be8)', 'ARRAY(0x100e71 +cd0)', 'ARRAY(0x100eb5bd0)', 'ARRAY(0x100eba628)') called at /Library +/Perl/5.10.0/Net/SSH/Expect.pm line 213 Net::SSH::Expect::login('Net::SSH::Expect=HASH(0x100e71bb0)') +called at ./deploy_cluster.pl line 235 main::ssh_login('****-idx-dev3.****.****.com', 'user', 'passwo +rd') called at ./deploy_cluster.pl line 187 main::copy_exist_to_old_all_servers('ARRAY(0x100e70ef0)', 'ARR +AY(0x100e71448)') called at ./deploy_cluster.pl line 67 spawn id(5): list of patterns: #1: -re `(?-xism:\\(yes/no\\)\\?\\s*$)' #2: -re `(?-xism:[Pp]assword.*?:|[Pp]assphrase.*?:)' #3: -re `(?-xism:ogin:\\s*$)' #4: -re `(?-xism:REMOTE HOST IDEN)' spawn id(5): Does `' match: pattern #1: -re `(?-xism:\\(yes/no\\)\\?\\s*$)'? No. pattern #2: -re `(?-xism:[Pp]assword.*?:|[Pp]assphrase.*?:)'? No. pattern #3: -re `(?-xism:ogin:\\s*$)'? No. pattern #4: -re `(?-xism:REMOTE HOST IDEN)'? No. spawn id(5): Does `Last login: Thu Oct 8 11:11:31 2015 from ****-idx- +dev1.****.****.com\r\r\n' match: pattern #1: -re `(?-xism:\\(yes/no\\)\\?\\s*$)'? No. pattern #2: -re `(?-xism:[Pp]assword.*?:|[Pp]assphrase.*?:)'? No. pattern #3: -re `(?-xism:ogin:\\s*$)'? No. pattern #4: -re `(?-xism:REMOTE HOST IDEN)'? No. spawn id(5): Does `Last login: Thu Oct 8 11:11:31 2015 from ****-idx- +dev1.****.****.com\r\r\n\033]0;****-idx-dev3.****.****.com:/Users/use +r # \007' match: pattern #1: -re `(?-xism:\\(yes/no\\)\\?\\s*$)'? No. pattern #2: -re `(?-xism:[Pp]assword.*?:|[Pp]assphrase.*?:)'? No. pattern #3: -re `(?-xism:ogin:\\s*$)'? No. pattern #4: -re `(?-xism:REMOTE HOST IDEN)'? No. spawn id(5): Does `Last login: Thu Oct 8 11:11:31 2015 from ****-idx- +dev1.****.****.com\r\r\n\033]0;****-idx-dev3.****.****.com:/Users/use +r # \007\033[?1034h****-idx-dev3:~ user$ ' match: pattern #1: -re `(?-xism:\\(yes/no\\)\\?\\s*$)'? No. pattern #2: -re `(?-xism:[Pp]assword.*?:|[Pp]assphrase.*?:)'? No. pattern #3: -re `(?-xism:ogin:\\s*$)'? No. pattern #4: -re `(?-xism:REMOTE HOST IDEN)'? No. Starting EXPECT pattern matching... at /System/Library/Perl/Extras/5.10.0/Expect.pm line 561. Expect::expect('Expect=GLOB(0x100eba4c0)', 10) called at /Libr +ary/Perl/5.10.0/Net/SSH/Expect.pm line 580 Net::SSH::Expect::_sec_expect('Net::SSH::Expect=HASH(0x100e71b +b0)', 10) called at /Library/Perl/5.10.0/Net/SSH/Expect.pm line 343 Net::SSH::Expect::peek('Net::SSH::Expect=HASH(0x100e71bb0)') c +alled at /Library/Perl/5.10.0/Net/SSH/Expect.pm line 209 Net::SSH::Expect::__ANON__('ARRAY(0x100eb5678)') called at /Sy +stem/Library/Perl/Extras/5.10.0/Expect.pm line 828 Expect::_multi_expect(10, 'ARRAY(0x100eb59a8)', 'ARRAY(0x100eb +5e70)') called at /System/Library/Perl/Extras/5.10.0/Expect.pm line 5 +65 Expect::expect('Expect=GLOB(0x100eba4c0)', 10, 'ARRAY(0x100eba +7a8)', 'ARRAY(0x100eb5be8)', 'ARRAY(0x100e71cd0)', 'ARRAY(0x100eb5bd0 +)', 'ARRAY(0x100eba628)') called at /Library/Perl/5.10.0/Net/SSH/Expe +ct.pm line 580 Net::SSH::Expect::_sec_expect('Net::SSH::Expect=HASH(0x100e71b +b0)', 10, 'ARRAY(0x100eba7a8)', 'ARRAY(0x100eb5be8)', 'ARRAY(0x100e71 +cd0)', 'ARRAY(0x100eb5bd0)', 'ARRAY(0x100eba628)') called at /Library +/Perl/5.10.0/Net/SSH/Expect.pm line 213 Net::SSH::Expect::login('Net::SSH::Expect=HASH(0x100e71bb0)') +called at ./deploy_cluster.pl line 235 main::ssh_login('****-idx-dev3.****.****.com', 'user', 'passwo +rd') called at ./deploy_cluster.pl line 187 main::copy_exist_to_old_all_servers('ARRAY(0x100e70ef0)', 'ARR +AY(0x100e71448)') called at ./deploy_cluster.pl line 67 spawn id(5): list of patterns: spawn id(5): Does `Last login: Thu Oct 8 11:11:31 2015 from ****-idx- +dev1.****.****.com\r\r\n\033]0;****-idx-dev3.****.****.com:/Users/use +r # \007\033[?1034h****-idx-dev3:~ user$ ' match: Uncaught exception from user code: SSHAuthenticationError Login timed out. The input stream curre +ntly has the contents bellow: Last login: Thu Oct 8 11:11:31 2015 fr +om ****-idx-dev1.****.****.com ****-idx-dev3:~ user$ at /System/Library/Perl/Extras/5.10.0/Expect.pm + line 828. at /Library/Perl/5.10.0/Net/SSH/Expect.pm line 209. Net::SSH::Expect::__ANON__('ARRAY(0x100eb5678)') called at /Sy +stem/Library/Perl/Extras/5.10.0/Expect.pm line 828 Expect::_multi_expect(10, 'ARRAY(0x100eb59a8)', 'ARRAY(0x100eb +5e70)') called at /System/Library/Perl/Extras/5.10.0/Expect.pm line 5 +65 Expect::expect('Expect=GLOB(0x100eba4c0)', 10, 'ARRAY(0x100eba +7a8)', 'ARRAY(0x100eb5be8)', 'ARRAY(0x100e71cd0)', 'ARRAY(0x100eb5bd0 +)', 'ARRAY(0x100eba628)') called at /Library/Perl/5.10.0/Net/SSH/Expe +ct.pm line 580 Net::SSH::Expect::_sec_expect('Net::SSH::Expect=HASH(0x100e71b +b0)', 10, 'ARRAY(0x100eba7a8)', 'ARRAY(0x100eb5be8)', 'ARRAY(0x100e71 +cd0)', 'ARRAY(0x100eb5bd0)', 'ARRAY(0x100eba628)') called at /Library +/Perl/5.10.0/Net/SSH/Expect.pm line 213 Net::SSH::Expect::login('Net::SSH::Expect=HASH(0x100e71bb0)') +called at ./deploy_cluster.pl line 235 main::ssh_login('****-idx-dev3.****.****.com', 'user', 'passwo +rd') called at ./deploy_cluster.pl line 187 main::copy_exist_to_old_all_servers('ARRAY(0x100e70ef0)', 'ARR +AY(0x100e71448)') called at ./deploy_cluster.pl line 67 Closing spawn id(5). at /System/Library/Perl/Extras/5.10.0/Expect.pm line 1431. Expect::hard_close('Expect=GLOB(0x100eba4c0)') called at /Syst +em/Library/Perl/Extras/5.10.0/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x100eba4c0)') called at /Library +/Perl/Updates/5.10.0/Carp.pm line 100 eval {...} called at /Library/Perl/Updates/5.10.0/Carp.pm line + 100 spawn id(5) closed. Pid 3237 of spawn id(5) terminated, Status: 0xFF00 ****-idx-dev1:manual user$

      Since you state that when you manually ssh you are not asked for a username/password, it sounds as if you are logging in with the same username as on the local machine with a public key pair. In that case, in place of the login() call you may do something like this:

      # $wait_time previously defined, in seconds # $password previously defined if ( ! $ssh->run_ssh() ) { if ( $ssh->waitfor( "ontinue connecting", $wait_time ) ) { $ssh->send("yes"); } if ( $ssh->waitfor( "ssword", $wait_time ) ) { $ssh->send( $password ); } if ( $ssh->waitfor( "ast login", $wait_time ) ) { # logged in } else { # unexpected error return undef; } } # connected, continue on your way

      Hope that helps.

      Update: 2015-10-07
      Changed variable name to make snippet more readable.