perl 采集入库脚本分享

#!/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->execute();
}
#####MYSQL UPDATE SUB END #####

#sub SCselect {
# my $sql = shift @_;
# my $myselect = $dbh->prepare($sql);
# $myselect->execute();
#  while($hostinfo = $myselect->fetchrow_hashref()) { print “$type\n” ;print “$hostinfo->{$type} \n” ;}
#}

#####MYSQL SELECT SUB START#####
sub shencan {
my @shencan = @_;
foreach $type (@shencan){
my $sql = “select * from shencan.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 $type1 =shencan “type”;
chomp($type1);
#####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 $ep53 =`dig \@127.0.0.1 www.qq.com >/dev/null && echo ok||echo bad`;
chomp($ep53);
update “update shencan.FC set ep53='$ep53′ 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 $ep80 =`curl -H “Host:www.qq.com” -o /dev/null -s -w “%{http_code}” http://$IP`;
chomp($ep80);
update “update shencan.FC set ep80='$ep80′ 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 =split(/\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+/,$_);
my $FC =”$fc1[2]“;
if($FC ge “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);
######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 $type1){

}else{
update “update shencan.FC set type='$TYPE' where hostname='$HOSTNAME'”;
}

if($FCVER1 eq $fdns){
}else{
update “update shencan.FC set fdnsversion='$FCVER1′ 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'”;
(0)

相关推荐

  • perl 采集入库脚本分享

    #!/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-&

  • BAT批处理一键生成APK包脚本分享

    BAT批处理一键生成APK包脚本分享 将本bat放到cocos2dx目录下你的工程的project.android下(需修改变量). ASmaker 用来将Resources文件夹下的lua文件批量加密 算法参考我之前的rc4算法实现. 每次打包apk前 svn 最新的工程代码 和 cocos2dx引擎代码. @echo off rem 工具路径 set JAVA_HOME = "C:\Program Files\Java\jdk1.8.0_05" set ANT_HOME = &qu

  • 解决dede生成静态页和动态页转换的一些问题,及火车采集入库生成动态的办法

    -------------------------------------------------------- 风十三 落伍首发  转载请注明作者和出处 ------------------------------------------------------ 1.如何修改默认发布为动态页: 这个其实很简单,会改html就可以了!把dede文件夹打开,用编辑器打开article_add.php,找到<td width="90">发布选项:</td>     

  • linux系统使用python获取cpu信息脚本分享

    linux系统使用python获取cpu信息脚本分享 复制代码 代码如下: #!/usr/bin/env Pythonfrom __future__ import print_functionfrom collections import OrderedDictimport pprint def CPUinfo():    ''' Return the information in /proc/CPUinfo    as a dictionary in the following format:

  • 也谈采集入库的技术

    落伍的贴也看了很多了,发现了很多讲小偷技术的,如精华贴里的--小偷程序原理和简单示例: [url]http://www.im286.com/viewthread.php?tid=407182&extra=page%3D1[/url] 等等,也有提供采集程序下载的,但我还没看到一篇完整的入库的文章,或许是我看的贴少吧.虽然不是很深奥,我还是讲讲吧,希望高手别见笑啦,以前发了个原创的影视系 统,却没落伍,这次再求落伍啦,希望大家帮顶下,也希望我能落伍!! 入库也和小偷一样,要先得到需入库的部分,我这

  • 实用自动化运维Python脚本分享

    并行发送sh命令 pbsh.py #!/usr/bin/python # -*- coding: UTF-8 -*- import paramiko import sys import threading #Copy local file to remote server. def sshclient_scp(hostname, port, username, password, local_path, remote_path): t = paramiko.Transport((hostname

  • Mysql数据库定时备份脚本分享

    BackUpMysql.sh脚本 #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH #数据库ip DBHOST='' #数据库用户名 DBUSER='' #数据库用密码 DBPASSWD='' #需要备份的数据库,多个数据库用空格分开 DBNAME='' #备份时间 backtime=`date +%Y-%m-%d_%H%M%S` #备份路径(当前目录) BACKPA

  • mysql常用备份命令和shell备份脚本分享

    备份多个数据库可以使用如下命令: mysqldump -uroot -p123456 --databases test1 test2 test3 > /home/test/dump.sql; 恢复备份: source dump.sql --在mysql命令行中输入该命令即可恢复 备份整个数据库: mysqldump -uroot -123456 -A > all.sql 备份整个数据库结构: mysqldump -uroot -p123456 -P3306 -A -d > all_002

  • 4个的Python自动化脚本分享

    目录 1.将 PDF 转换为音频文件 2.从列表中播放随机音乐 3.不再有书签了 4.清理下载文件夹 前言: 大家平时有没有注意到你每天可能会执行许多的重复的任务,例如阅读 pdf.播放音乐.打开书签.清理文件夹等等. 我将分享4个实用的python的自动化脚本,无需手动一次又一次地完成这些任务,非常方便. 1.将 PDF 转换为音频文件 脚本可以将 pdf 转换为音频文件,原理也很简单,首先用 PyPDF 提取 pdf 中的文本,然后用 Pyttsx3 将文本转语音.关于文本转语音,你还可以看

  • Python实现自动玩连连看的脚本分享

    目录 序言 实现步骤 全部代码 序言 最近女朋友在玩连连看,玩了一个星期了还没通关,真的是菜. 我实在是看不过去了,直接用python写了个脚本代码,一分钟一把游戏. 快是快,就是联网玩容易被骂,嘿嘿~ 实现步骤 模块导入 import cv2 import numpy as np import win32api import win32gui import win32con from PIL import ImageGrab import time import random 窗体标题 用于定

随机推荐