
zjedzmnie
Novice
Oct 2, 2008, 1:53 AM
Post #7 of 8
(507 views)
|
|
Re: [KevinR] copy from cisco router
[In reply to]
|
Can't Post
|
|
#!/usr/bin/perl -w use strict; use Expect; my $sendmail="/usr/sbin/sendmail"; my @tmp; my $timeout=60; my $alltext="Content-Type: text/plain; charset=\"iso-8859-2\" Subject: Nr tel ISDN naszych biur HSB "; my $e = new Expect; $e->log_user(1); my $fucked=0; $e->spawn("/usr/bin/ssh -l ************* *************"); sleep 1; $e->expect($timeout, [qr/password:/ => sub {my $in=shift;$in->send("************8\r")}], [timeout => sub {$fucked=1}]); if ($fucked==1) { $alltext.="DMZ: login error\n"; } else { $e->expect($timeout,'-re','^(\w|\d|-)+?#'); $e->send("terminal length 0\r"); $e->expect($timeout,'-re','^(\w|\d|-)+?#'); $e->send("show log | i ISDN-6-DISCONNECT\r"); $e->expect($timeout,'-re','^(\w|\d|-)+?#'); my $logi=$e->before(); $logi=~s/\r//mg; $logi=~s/^\s+//mg; @tmp=split("\n",$logi); sleep 1; for(my $i=1; $i<=$#tmp; $i++) { if ($tmp[$i]=~/^(.*?)(\d{9})\s(h-\w{4,5}-)(\d{3})(.*?)$/) { $tmp[$i]=~s/^(.*?)(\d{9})\s(h-\w{4,5}-)(\d{3})(.*?)$/$2\t$3$4\n/; #print "$tmp[$i]\n"; } else { $tmp[$i]=~s/^(.*?)$/\n/; } } } my @tosort; for(my $j=0; $j<=$#tmp;$j++) { if ($tmp[$j]=~/^(\d{9})\t(h-\w{4,5}-)(\d{3})$/) { $tosort[$j]=$tmp[$j]; } } my @sorted = sort tableSorter @tosort; sub tableSorter ($$) { my($row1, $row2) = @_; my $column1comparison = $row1->[2] cmp $row2->[2]; if($column1comparison != 0) { return $column1comparison; } my $column2comparison = $row1->[1] cmp $row2->[1]; if($column2comparison != 0) { return $column2comparison; } return $row1->[0] cmp $row2->[0]; } $alltext.="@sorted\n"; $e->send("logout\r"); open(SENDMAIL, "| $sendmail -oi -t -f '***********@************'" ) or die "Can't open sendmail: $!\n"; print SENDMAIL "To: <**************\@*************>\n"; print SENDMAIL $alltext; close(SENDMAIL) or warn "Sendmail didn't close nicely: $!\n"; And I have problem in line (my $column1comparison = $row1->[2] cmp $row2->[2];) Can't use string ("999999999 h-aaaa-100 ") as an ARRAY ref while "strict refs" in use at ./sho_log_tel_sort_save.pl line 99.
|