#!/usr/bin/perl-w
useDBI;
usePOSIXqw(strftime);
my$dbh=DBI->connect(“DBI:mysql:shencan:111.1.32.153:3306″,”shencan”,”shencan”);
#my$sql=“select*fromshencan.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=“updateshencan.LVSsetnode='CBN_CQ'wherehostname='CBN-CQ-1-3Z2′”;
#my$STH=$dbh->prepare($SQL);
#$STH->execute();
#####MYSQLUPDATESUBSTART#####
subupdate{
my$sql=shift@_;
my$mysqlupdate=$dbh->prepare($sql);
$mysqlupdate->execute();
}
#####MYSQLUPDATESUBEND#####
#subSCselect{
#my$sql=shift@_;
#my$myselect=$dbh->prepare($sql);
#$myselect->execute();
#while($hostinfo=$myselect->fetchrow_hashref()){print“$type\n”;print“$hostinfo->{$type}\n”;}
#}
#####MYSQLSELECTSUBSTART#####
subshencan{
my@shencan=@_;
foreach$type(@shencan){
my$sql=“select*fromshencan.FCwherehostname='$HOSTNAME'”;
my$myselect=$dbh->prepare($sql);
$myselect->execute();
while($hostinfo=$myselect->fetchrow_hashref()){
return“$hostinfo->{$type}”;
}
}
}
#####MYSQLSELECTSUBEND######
#####MYSQLSELECTSTART#######
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$type1=shencan“type”;
chomp($type1);
#####MYSQLSELECTEND######
####CHECKNGVERSIONSTART#####
my$NG=`rpm-qNG`;
chomp($NG);
####CHECKNGVERSIONEND#####
####CHECKAMRVERSIONSTART#####
my$AMR=`rpm-qAMR`;
chomp($AMR);
####CHECKAMRVERSIONEND#####
####CHECKOHVERSIONSTART#####
my$OH=`rpm-qOH`;
chomp($OH);
####CHECKOHVERSIONEND#####
####CHECKDMVERSIONSTART#####
my$DM=`rpm-qDM`;
chomp($DM);
####CHECKDMVERSIONEND#####
####CHECKMFTTVERSIONSTART#####
my$MFTT=`rpm-qMFTT`;
chomp($MFTT);
####CHECKMFTTVERSIONEND#####
####CHECKCPISBINVERSIONSTART#####
my$CPISBIN=`rpm-qCPISBIN`;
chomp($CPISBIN);
####CHECKCPISBINVERSIONEND#####
####CHECKNODESTART#####
my@NODE=split(/-/,$HOSTNAME);
$NODE=“$NODE[0]_$NODE[1]“;
####CHECKNODEEND#####
####CHECKARCHSTAR#####
my$ARCH=`arch`;
chomp($ARCH);
#####CHECKARCHEND#####
####CHECKEP53STATUSANDUPDATESTART#####
my$ep53=`dig\@127.0.0.1www.qq.com>/dev/null&&echook||echobad`;
chomp($ep53);
update“updateshencan.FCsetep53='$ep53′wherehostname='$HOSTNAME'”;
####CHECKEP53STATUSANDUPDATEEND#####
####CHECKEP80STATUSANDUPDATESTART#####
my$GW=`route-n|awk‘\$1==”0.0.0.0″{print\$2}'|awk-F”.”‘{print\$1″.”\$2″.”\$3}'`;
chomp($GW);
my$IP=`ipa|grepinet|grep$GW|awk-F”[/]”‘{print\$6}'`;
chomp($IP);
my$ep80=`curl-H“Host:www.qq.com”-o/dev/null-s-w“%{http_code}”http://$IP`;
chomp($ep80);
update“updateshencan.FCsetep80='$ep80′wherehostname='$HOSTNAME'”;
####CHECKEP80STATUSANDUPDATEEND#####
print“NG:$NGARM:$AMROH:$OHDM:$DMMFTT:$MFTTCPISBIN:$CPISBIN\n”;
print“$HOSTNAMENODE:$NODEOS:$osarch:$archFC:$FCfdns:$fdnsng:$ng\n”;
#####CHECKOSSTART######
subOS{
open(OS,”</etc/issue”);
@line=<OS>;
$line=$line[0];
chomp($line);
my@os=split(/\s+|\(|\)/,$line);
if($os[0]ge“Red”){
$SC=“REHL$os[6].$os[10]“;
}else{
$SC=“$os[0]$os[2]“;
}
}
OS;
close(OS);
#####CHECKOSEND######
######CHECKFDNSORNAMEVERSIONSTART######
open(FDNS,”</etc/ChinaCache/app.d/cpisbm.amr”);
while(<FDNS>){
if(/RestartCmd/){
my@fc1=split(/\s+/,$_);
my$FC=”$fc1[2]“;
if($FCge“named”){
$FCVER=`/usr/sbin/named-v`;
chomp($FCVER);
my@FC1=split(/\s+/,$FCVER);
$FCVER1=”$FC1[0]$FC1[1]“;
}else{
$FCVER=`/FlexiDNS/application/sbin/fdns-v`;
chomp($FCVER);
my@FC1=split(/\s+/,$FCVER);
$FCVER1=”$FC1[0]$FC1[1]“;
}
}
}
close(FDNS);
######CHECKFDNSORNAMEVERSIONEND######
#####CHECKFCVERSIONANDTYPESTART######
open(FC,”</etc/ChinaCache/app.d/cpisfc.amr”);
while(<FC>){
if(/RestartCmd/){
my@squid=split(/\s+/,$_);
my$SQUID=”$squid[2]“;
if($SQUIDge“squid”){
$SQUIDVER=`/usr/local/squid/sbin/squid-v|head-n1|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);
#####CHECKFCVERSIONANDTYPEEND######
####ChangeMYSQL#######
if($SQUIDVEReq$FC){
}else{
update“updateshencan.FCsetfcversion='$SQUIDVER'wherehostname='$HOSTNAME'”;
}
if($NGeq$ng){
}else{
update“updateshencan.FCsetngversion='$NG'wherehostname='$HOSTNAME'”;
}
if($DMeq$dm){
}else{
update“updateshencan.FCsetdmversion='$DM'wherehostname='$HOSTNAME'”;
}
if($AMReq$amr){
}else{
update“updateshencan.FCsetamrversion='$AMR'wherehostname='$HOSTNAME'”;
}
if($OHeq$oh){
}else{
update“updateshencan.FCsetohversion='$OH'wherehostname='$HOSTNAME'”;
}
if($CPISBINeq$cpisbin){
}else{
update“updateshencan.FCsetcpisbinversion='$CPISBIN'wherehostname='$HOSTNAME'”;
}
if($NODEeq$node){
}else{
update“updateshencan.FCsetnode='$NODE'wherehostname='$HOSTNAME'”;
}
if($TYPEeq$type1){
}else{
update“updateshencan.FCsettype='$TYPE'wherehostname='$HOSTNAME'”;
}
if($FCVER1eq$fdns){
}else{
update“updateshencan.FCsetfdnsversion='$FCVER1′wherehostname='$HOSTNAME'”;
}
if($SCeq$os){
}else{
update“updateshencan.FCsetOS='$SC'wherehostname='$HOSTNAME'”;
}
if($ARCHeq$arch){
}else{
update“updateshencan.FCsetarch='$ARCH'wherehostname='$HOSTNAME'”;
}
my$time=strftime“%Y-%m-%d_%H:%M:%S”,localtime;
chomp($time);
update“updateshencan.FCsetlmtime='$time'wherehostname='$HOSTNAME'”;