In its broadest sense, learning can be defined as a process of progressive change from ignorance to knowledge, and from indifference to understanding....

统一收集每台server的空间使用量

上一篇 / 下一篇  2008-03-22 16:51:30 / 个人分类:Shell & Perl

简单的perl脚本从一台linux主机来统一收集每台SERVER disk空间使用量,用SHELL写一个可能更容易懂.
1.在dmsdb  DB中添加一table 将所要收集的server添加到TAB_HOSTS 表中,栏位至少有ip hostname status(这个便于控制关停收集某台)
2.根据上篇文章SSH login without password配置ssh 登陆
3.还要有PERL DBI组件
主要script如下,可以做小修改超过多少percent就发mail出来报警和将每天的记录在DB中.

#!/usr/bin/perl -w
 
use strict;
use DBI qw(:sql_types);
 
$ENV{"ORACLE_HOME"} = "/opt/oracle/product/9ir2";
 
my $dbh = DBI->connect( 'dbi:Oracle:dmsdb',
                        'username',
                        'password',
                                                { RaiseError => 1, AutoCommit => 0 }
                      ) || die "Database connection not made: $DBI::errstr" ;
 
my $DateTime = `date +'%Y-%m-%d'`;
my $p1 = " " x 10;
chomp($DateTime);
 
my $sth = $dbh->prepare(qq{SELECT IP,HOSTNAME FROM TAB_HOSTS WHERE STATUS = 'UP'});
$sth->execute();
 
while ( my ($Ip,$HostName) = $sth->fetchrow_array() ) {
                my @OsInfo = split(/\s+/,`ssh -l smmon $Ip "uname -sn"`);
 
                if ($OsInfo[0] =~ /Linux/) {
                        my @DiskList = `ssh -l smmon $Ip df -k`;
                        print "\n\n\n";
                        print "$DateTime ";
                        print "$HostName $Ip \n";
                        print "@DiskList";
                }
                elsif($OsInfo[0] =~ /HP-UX/) {
                        my @DiskList = `ssh -l smmon $Ip bdf`;
                        print "\n\n\n";
                        print "$DateTime ";
                        print "$HostName $Ip\n";
                        print "@DiskList";
                }
}
 
$sth->finish;
 
$dbh->disconnect();


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-12-03  
 123456
78910111213
14151617181920
21222324252627
28293031   

数据统计

  • 访问量: 6793
  • 日志数: 928
  • 影音数: 2
  • 文件数: 2
  • 书签数: 3
  • 建立时间: 2008-02-17
  • 更新时间: 2008-12-02

RSS订阅

Open Toolbar