ollyg / Net-Appliance-Session

Development of Net::Appliance::Session Perl distribution
https://metacpan.org/pod/Net::Appliance::Session
13 stars 6 forks source link

multi-host processing #18

Closed matt26 closed 11 years ago

matt26 commented 11 years ago

Hi,

I'd like to use your module to connect to multiple hosts sequentially. Therefore I pass a file (one ip-address per line) to my script which I do open with:

open(IPFILE, "<$IPFILE") or die "Could not open $IPFILE.\n" ;

Then I do a loop to open a session to each host with:

foreach $host () { chomp($host); eval { $session = Net::Appliance::Session->new(add_library => $phrasebook_dir, personality => 'hph3c', transport => 'SSH', host => $host, timeout => $login_timeout); $session->set_global_log_at('debug'); #turn on debugging(level:info, notice, debug) $session->connect(username => $username, password => $passwd); };

The issue I have is, when the IPFILE has exactly one line (one ip-address) in it everything works fine. But as soon as I add a second (empty or ip-address) line to the file the script stops working. What I see from debugging is the following:

Good: [ 0.042721] pr finding prompt [ 0.107548] tr creating Net::Telnet wrapper for ssh [ 0.112081] tr connecting with: ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -l srv-spec 1.1.1.1

Bad: [ 0.043921] pr finding prompt [ 0.110460] tr creating Net::Telnet wrapper for ssh ' 0.115324] tr connecting with: ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -l srv-spec '1.1.1.1 [ 5.692846] du SEEN: : hostname nor servname provided, or not known

Somehow there are two ' added and I cannot see why. Any idea or help?

Thanks in advance, Matthias

matt26 commented 11 years ago

Some additional info on the version I use $ perl -V Summary of my perl5 (revision 5 version 14 subversion 2) configuration:

Platform: osname=cygwin, osvers=1.7.15(0.26053), archname=cygwin-thread-multi-64int uname='cygwin_nt-5.1 winxp 1.7.15(0.26053) 2012-05-09 10:25 i686 cygwin ' config_args='-de -Dlibperl=cygperl5_14.dll -Dcc=gcc-4 -Dld=g++-4 -Darchname=i686-cygwin-threads-64int -Dmksymlinks -Dusethreads -Accflags=-g' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc-4', ccflags ='-DPERL_USE_SAFE_PUTENV -USTRICT_ANSI__ -g -fno-strict-aliasing -pipe -fstack-protector', optimize='-O3', cppflags='-DPERL_USE_SAFE_PUTENV -USTRICT_ANSI__ -g -fno-strict-aliasing -pipe -fstack-protector' ccversion='', gccversion='4.5.3', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='g++-4', ldflags =' -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /usr/lib /lib libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat perllibs=-ldl -lcrypt libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=cygperl5_14.dll gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags=' --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -L/usr/local/lib -fstack-prot ector'

Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_PRESERVE_IVUV PERL_USE_SAFE_PUTENV USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API Locally applied patches: Bug#55162 File::Spec::case_tolerant performance CYG07 $vendorarch/auto/.rebase CYG15 static Win32CORE CYG17 cyg-1.7 paths-utf8 0c612ce82 Fix building static extensions on cygwin, -UUSEIMPORTLIB 1bac5ecc1 Fix 64-bit threading sv.c: S_anonymise_cv_maybe Cygwin::sync_winenv added Built under cygwin Compiled at Jul 12 2012 14:17:21 @INC: /usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int /usr/lib/perl5/site_perl/5.14 /usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int /usr/lib/perl5/vendor_perl/5.14 /usr/lib/perl5/5.14/i686-cygwin-threads-64int /usr/lib/perl5/5.14 /usr/lib/perl5/site_perl/5.10 /usr/lib/perl5/vendor_perl/5.10 /usr/lib/perl5/site_perl/5.8 . $ perl -MNet::CLI::Interact\ 999 Net::CLI::Interact version 999 required--this is only version 2.131260. BEGIN failed--compilation aborted.

$ perl -MNet::Appliance::Session\ 999 Net::Appliance::Session version 999 required--this is only version 4.131260. BEGIN failed--compilation aborted.

ollyg commented 11 years ago

Hi Matthias,

Unfortunately I've not been able to reproduce your problem :-(

I wrote a very simple script just like yours, and it works OK. I tried your code using foreach, and also a slightly different way which does the same thing:

open(IPFILE, "<", "./hosts")
    or die "Could not open hosts\n";

while (my $host = <IPFILE>) {
    chomp $host;
    # session code here
}

The only thing I can suggest is to immediately print out the current host at the top of the loop (after the chomp) to make sure there are no odd characters in the IP.

regards, oliver.

ollyg commented 11 years ago

Thinking about it.... one reason the quotes could appear is if there's trailing whitespace on the IP. You could try:

$host =~ s/\s+//g;

at the top of the loop, to make sure.

regards, oliver.