#!/usr/bin/perl-w use DBI;
Use POSIX QW (strftime);
My $dbh = Dbi->connect ("Dbi:mysql:shencan:111.1.32.153:3306″", "Shencan", "Shencan"); #my $sql = "SELECT * from Shencan.
LVS ";
#my $sth = $dbh->prepare ($sql);
# $sth->execute ();
My $HOSTNAME = ' HOSTNAME ';
Chomp ($HOSTNAME);
My $type;
My $hostinfo; #while ($hostname = $sth->fetchrow_hashref ()) #{# print ' $hostname->{hostname} $hostname->{hostip}\n '; #} #my
@value; #while (@value = $sth->fetchrow_array ()) #{# print ' @value \ n '; #} #my $SQL = ' Update Shencan.
LVS set node= ' Cbn_cq ' where hostname= ' cbn-cq-1-3z2′ ';
#my $STH = $dbh->prepare ($SQL);
# $STH->execute (); # #MYSQL UPDATE Sub START ##### sub update{My $sql = Shift @_, my $mysqlupdate = $dbh->prepare ($sql); $mysqlupdate-&
Gt;execute (); #MYSQL UPDATE SUB-end ##### #sub scselect {# i $sql = shift @_; # my $myselect = $dbh->prepare ($sql); # $mysel
Ect->execute (); # while ($hostinfo = $myselect->fetchrow_hashref ()) {print "$type \ n";p rint "$hostinfo->{$type} \ n ";} # # # # #MYSQL Select Sub start##### sub Shencan {my @shencan = @_; foreach $type (@shencan) {My $sql = ' select * from sh Encan.
FC where hostname= ' $HOSTNAME ';
My $myselect = $dbh->prepare ($sql);
$myselect->execute ();
while ($hostinfo = $myselect->fetchrow_hashref ()) {return "$hostinfo->{$type}";}
#MYSQL Select SUB end###### #MYSQL Select START ####### my $FC =shencan "fcversion";
Chomp ($FC);
My $os = shencan "OS";
Chomp ($os);
My $arch = Shencan "Arch";
Chomp ($arch);
My $fdns =shencan "fdnsversion";
Chomp ($fdns);
My $ng = Shencan "Ngversion";
Chomp ($ng);
My $amr =shencan "amrversion";
Chomp ($AMR);
My $oh =shencan "ohversion";
Chomp ($OH);
My $dm = Shencan "Dmversion";
Chomp ($DM);
My $cpisbin = Shencan "Cpisbinversion";
Chomp ($cpisbin);
My $node = shencan "Node";
Chomp ($node);
My $type 1 =shencan "type";
Chomp ($type 1);
# #MYSQL SELECT end###### ### #CHECK ng VERSION start##### my $NG = ' rpm-q NG ';
Chomp ($NG); ### #CHECK NG VERSION ENd##### ### #CHECK amr VERSION start##### my $AMR = ' rpm-q amr ';
Chomp ($AMR);
### #CHECK AMR version end##### ### #CHECK OH version start##### my $OH = ' rpm-q OH ';
Chomp ($OH);
### #CHECK OH version end##### ### #CHECK DM version start##### my $DM = ' rpm-q DM ';
Chomp ($DM);
### #CHECK DM version end##### ### #CHECK MFTT version start##### my $MFTT = ' rpm-q mftt ';
Chomp ($MFTT);
### #CHECK MFTT version end##### ### #CHECK cpisbin version start##### my $CPISBIN = ' rpm-q cpisbin ';
Chomp ($CPISBIN);
### #CHECK cpisbin VERSION end##### ### #CHECK NODE start##### my @NODE =split (/-/, $HOSTNAME);
$NODE = "$NODE [0]_$node[1]";
### #CHECK NODE end##### ### #CHECK arch STAR ##### my $ARCH = ' arch ';
Chomp ($ARCH); # # #CHECK ARCH end ##### ### #CHECK EP53 STATUS and UPDATE start##### my $ep # = ' Dig \@127.0.0.1 www.qq.com && echo ok| |
echo Bad ';
Chomp ($ep 53); Update "Update Shencan.
FC set ep53= ' $ep 53′where hostname= ' $HOSTNAME '; ### #CHECK EP53 STATUS and UPDATE end##### ### #CHECK EP80 statuS and UPDATE start##### my $GW = ' route-n |awk ' \$1== ' 0.0.0.0″{print \$2} ' |awk-f '. ' {print \$1″. ' \$2″. "
\$3} ';
Chomp ($GW);
My $IP = ' IP a|grep inet|grep $GW |awk-f ' [/] ' ' {print\$6} ';
Chomp ($IP);
My $ep "curl-h" Host:www.qq.com "-o/dev/null-s-W"%{http_code} "http://$IP";
Chomp ($ep 80); Update "Update Shencan.
FC set ep80= ' $ep 80′where hostname= ' $HOSTNAME ';
### #CHECK EP80 STATUS and UPDATE end##### print "NG: $NG ARM: $AMR OH: $OH DM: $DM mftt: $MFTT cpisbin: $CPISBIN \ n";
Print "$HOSTNAME NODE: $NODE OS: $os arch: $arch FC: $FC fdns: $fdns ng: $ng \ n"; # #CHECK OS start###### sub os {open (OS, </etc/issue); @line =<os>; $line = $line [0]; Chomp ($line); my @os =s
Plit (/\s+|\ (|\)/, $line); if ($os [0] ge "Red") {$SC = "rehl$os[6]. $os [10]";}
else{$SC = "$os [0] $os [2]";}}
OS;
Close (OS);
# #CHECK OS end###### ##### #CHECK fdns OR NAME VERSION start###### Open (Fdns, "</etc/chinacache/app.d/cpisbm.amr"); while (<FDNS>) {if (/restartcmd/) {my @fc1 =split (/\s+/,$_);$FC = "$FC 1[2]";
if ($FC ge "named") {$FCVER = '/usr/sbin/named-v '; chomp ($FCVER); my @FC1 =split (/\s+/, $FCVER); $FCVER 1= "$FC 1[0] $FC 1[1]"; }else{$FCVER = '/flexidns/application/sbin/fdns-v '; chomp ($FCVER); my @FC1 =split (/\s+/, $FCVER); $FCVER 1= "$FC 1[0] $FC 1
[1] ";
}} close (Fdns); ##### #CHECK fdns OR NAME VERSION end###### #CHECK fcversion and TYPE start###### open (FC, "</etc/chinacache/app.d/
Cpisfc.amr "); while (<FC>) {if (/restartcmd/) {my @squid =split (/\s+/,$_), my $SQUID = "$squid [2]"; if ($SQUID ge "squid") {$SQUIDVER
= '/usr/local/squid/sbin/squid-v|head-n 1 |awk ' {print ' V ' \$4} ';
Chomp ($SQUIDVER);
$TYPE = "Fc5″;
}else {$SQUIDVER = '/usr/local/flexicache/sbin/flexicache-v|awk ' {print \$3} '; Chomp ($SQUIDVER); $TYPE = "Fc6″;}}
Close (FC); # #CHECK Fcversion and TYPE end###### ### #Change MYSQL ####### if ($SQUIDVER eq $FC) {}else{update update shencan.
FC set fcversion= ' $SQUIDVER ' where hostname= ' $HOSTNAME '; } if ($NG eq $ng) {}else{update update shencan. FC Set Ngversion= ' $NG ' where hostname= ' $HOSTNAME '; } if ($DM eq $dm) {}else{update update shencan.
FC set dmversion= ' $DM ' where hostname= ' $HOSTNAME '; } if ($AMR eq $amr) {}else{update update shencan.
FC set amrversion= ' $AMR ' where hostname= ' $HOSTNAME '; } if ($OH eq $oh) {}else{update update shencan.
FC set ohversion= ' $OH ' where hostname= ' $HOSTNAME '; } if ($CPISBIN eq $cpisbin) {}else{update update shencan.
FC set cpisbinversion= ' $CPISBIN ' where hostname= ' $HOSTNAME '; } if ($NODE eq $node) {}else{update update shencan.
FC set node= ' $NODE ' where hostname= ' $HOSTNAME '; } if ($TYPE eq $type 1) {}else{Update update shencan.
FC set type= ' $TYPE ' where hostname= ' $HOSTNAME '; } if ($FCVER 1 eq $fdns) {}else{update update shencan.
FC set fdnsversion= ' $FCVER 1′where hostname= ' $HOSTNAME '; } if ($SC eq $os) {}else{update update shencan.
FC set os= ' $SC ' where hostname= ' $HOSTNAME '; } if ($ARCH eq $arch) {}else{update update shencan.
FC set arch= ' $ARCH ' where hostname= ' $HOSTNAME '; } My $time =Strftime "%y-%m-%d_%h:%m:%s", localtime;
Chomp ($time); Update "Update Shencan. FC set lmtime= ' $time ' where hostname= ' $HOSTNAME ';