脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - perl - perl 采集入库脚本分享

perl 采集入库脚本分享

2020-06-20 10:58perl教程网 perl

这篇文章主要介绍了perl 采集入库脚本分享,本文是以前自己用的脚本,使用的Mysql数据库,需要的朋友可以参考下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/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'”;

延伸 · 阅读

精彩推荐
  • perlperl命令行参数内建数组@ARGV浅析

    perl命令行参数内建数组@ARGV浅析

    这篇文章主要介绍了perl命令行参数内建数组@ARGV浅析,本文重点在于讲解@ARGV的用法,并通过实例来说明,需要的朋友可以参考下 ...

    perl教程网6162020-06-18
  • perlPerl的经典用法分享

    Perl的经典用法分享

    Perl的经典用法分享,学习perl的朋友可以参考下 ...

    脚本之家6562020-06-06
  • perlPerl从文件中读取字符串的两种实现方法

    Perl从文件中读取字符串的两种实现方法

    有时候我们需要从文件中读取字符串,这里简单介绍下, 需要的朋友可以参考下 ...

    脚本之家6252020-06-08
  • perlperl pop push shift unshift实例介绍

    perl pop push shift unshift实例介绍

    perl的pop跟push操作数组的最右边,shift跟unshift操作数组的最左边 ...

    脚本之家4612020-06-10
  • perlperl use vars pragma使用技巧

    perl use vars pragma使用技巧

    perl 中的vars是perl中的一个pragma(预编译指示符),专门用来预定义全局变量,这些预定义后的全局变量在qw()列表中,在整个引用perl文件中皆可使用,即便使...

    perl教程网6812020-06-16
  • perlperl常见问题集合之二

    perl常见问题集合之二

    哪些平台上有 Perl?要到哪里去找? Perl的标准发行版(由 perl 发展小组负责维护)仅以原始码形式发行。您可在 http: //www.perl.com/CPAN/src/latest.tar.gz处取得。这个档...

    脚本之家2102020-05-29
  • perlPerl List::Util模块使用实例

    Perl List::Util模块使用实例

    这篇文章主要介绍了Perl List::Util模块使用实例,本文给出扫描符合条件的某个列表并取出第一个符合条件的、求1到1000之间的和 、求一组数字的最大值与最小...

    脚本之家4712020-06-22
  • perlPerl使用nginx FastCGI环境做WEB开发实例

    Perl使用nginx FastCGI环境做WEB开发实例

    这篇文章主要介绍了Perl使用nginx FastCGI环境做WEB开发实例,实现了路由系统和模板系统,需要的朋友可以参考下...

    Perl教程网2412020-06-18