
richsark
User
Apr 23, 2009, 6:20 AM
Post #21 of 26
(4457 views)
|
|
Re: [1arryb] Help needed for my script
[In reply to]
|
Can't Post
|
|
Hello Larry, sorry for the delay, I was in self pity for a bit but I am back. When I put the ssh login in without eval mode Looks like it works ok, as you can see I don’t have access to several servers on Asia or EMEA. I expected the script to continue like it has been, but as you can see I get a time out I got lots of updates, and I am sorry if its long. Non-Eval Mode: ls-2: found=no init: found=no ls-1: found=yes ls-2: found=yes Could not login to irprns711b.ny.rich.com Could not login to proxys77.ny.rich.com init: found=no ls-1: found=no ls-2: found=no Could not login to gadns01.ct.sg.criche.com Could not login to gdns03.ct.sg.criche.com Could not login to xp0124.ssh.hk.sarkie.com Could not login to hxp0125.ssh.hk.sarkie.com Could not login to kxp0426.ssh.hk.sarkie.com Could not login to kkxp6127.sly.hk.sarkie.com Could not login to srbdns01.ct.sg.criche.com Could not login to tjp-dns-04.tk.jp.criche.com Could not login to tlp-dns-05.tk.jp.criche.com SSHAuthenticationError Login timed out. The input stream currently has the contents bellow: at /usr/lib/perl5/site_perl/5.10/Expect.pm line 828 When I put in eval mode, I get different responses: $ perl test3.pl init: found=no ls-1: found=no ls-2: found=no init: found=no ls-1: found=no ls-2: found=no init: found=no ls-1: found=no ls-2: found=no $ssh->login() failed: Login output was richsark's Password: at test3.pl line 43, <$in> line 1. init: found=no ls-1: found=no ls-2: found=no init: found=no ls-1: found=no ls-2: found=no init: found=no ls-1: found=no ls-2: found=yes init: found=no ls-1: found=yes ls-2: found=yes init: found=no ls-1: found=yes ls-2: found=yes $ssh->login() failed: Login output was Total users logged in under your name (via BoKS): 4 (1 on this host) Total users logged in (via BoKS): 14783 (1 on this host) Last Login 04/23/09 09:07:52 - 04/23/09 09:08:27 (inpdns111a.ky.sarkie.com:pts/1) ****** BoKS 6.5 ****** Last login: Thu Apr 23 08:37:32 2009 from 10.129.148.48 Could not chdir to home directory /home/richsark: No such file or directory $ at test3.pl line 43, <$in> line 5. $ssh->login() failed: Login output was Total users logged in under your name (via BoKS): 4 (1 on this host) Total users logged in (via BoKS): 14785 (1 on this host) Last Login 04/23/09 09:08:29 - 04/23/09 09:08:44 (inpdns111b.ny.sarkie.com:pts/1) ****** BoKS 6.5 ****** Last login: Thu Apr 23 08:37:50 2009 from 10.129.148.48 Could not chdir to home directory /home/richsark: No such file or directory $ at test3.pl line 43, <$in> line 5. init: found=no ls-1: found=yes ls-2: found=yes $ssh->login() failed: Login output was richsark's Password: at test3.pl line 43, <$in> line 70. The script still continues….. But.. there are some servers that have a different prompt versus the original we have in place. some servers when I SSH to have this senerio which I have to type in "yes" to continue: Could not create directory '/home/richsark.ssh'. The authenticity of host 'sarkie.ky.sarfish.com (19.97.6.15)' can't be established RSA key fingerprint is 96:42:39:ff:a4:3c:1a:17:7d:5b:7e:a4:8a:b7:3d:51. Are you sure you want to continue connecting (yes/no)? yes Failed to add the host to the list of known hosts (/home/richsark/.ssh/known_hosts). How can we had this to the script to allow such scenario, That may solve some of my login problems, but I think there me another underlying issue under the radar. This is my latest code: #!perl use strict; use warnings; use Net::SSH::Expect; open(my $out, ">log.txt") or die "Could not open log: $!\n"; my %Processed; ##### Step 1, read subnet.txt open(my $in, "<subnet.txt") or die "Could not open subnet.txt: $!\n"; while(<$in>) { chomp; ##### Step 2: run getzoneprof, and keep first 4 lines only my @getzoneprof = `./richsark-getzoneprof.exe -u xXx-p XxX -a $_ -o Sark1`; @getzoneprof = @getzoneprof[0..3]; ##### Find server name warn "Server not found for $_\n",next unless $getzoneprof[-1] =~ /dnsServers=(.+)/; my $dns_line = $1; my @dns = grep {length($_)>1} split(/[\s,]+/, $dns_line); foreach my $dns (@dns) { print next if $Processed{$dns}; $Processed{$dns} = 1; ##### ssh to server my $ssh = Net::SSH::Expect->new ( host => $dns, password=> '12345', user => 'rich', raw_pty => 1, timeout => 10 ); my $login_output; eval { $login_output = $ssh->login(); unless($login_output =~ /IT IS AN OFFENSE TO CONTINUE/) { # The die will be caught in the if ($@) {} block, below. die "Login output was $login_output"; } }; # Capture "normal" login errors + $ssh method exceptions. if ($@) { print "\$ssh->login() failed: $@\n"; $ssh->close(); next; } ##### run ls to look for files my $found='no'; print "init: found=$found\n"; my $ls = $ssh->exec("ls /opt/richsark/named/*.jnl"); $found='yes' if($ls and $ls =~ m|/opt/richsark/named/|); print "ls-1: found=$found\n"; $ls = $ssh->exec("ls /opt/richsark/named/sec_richsark/*.jnl"); $found='yes' if($ls and $ls =~ m|/opt/richsark/named/sec_richsark/|); print "ls-2: found=$found\n"; print $out "From zone $_ containing dnsserver \"$dns\" found=$found of presense of \"jnl\" files\n\n"; $ssh->close; } } close($out);
|