- 論壇徽章:
- 0
|
本帖最后由 wxm8000 于 2013-02-26 13:16 編輯
自己寫的一個批量遠程連接aix后檢查lsdev里指定的磁盤類型和對應(yīng)的lspath的數(shù)量,還挺好用,給大家分享一下,也請大家?guī)兔纯从惺裁吹胤叫枰倪M的,:wink:
要先裝IO-Tty,Expect,Net::SSH::Expect- [user@storage]$ cat chkPath
- #!/usr/bin/perl
- use Net::SSH::Expect;
- my $username = "user";
- my $password = "password";
- #檢查的磁盤類型為3PAR,如果是其他類型的可以在這里修改,比如XP等
- my $disktype = "3PAR";
- my $pid = 1;
- die "please give a filename for the ip list!\n" if @ARGV ne 1;
- die "please give a true file for the ip list!\n" if ! -f $ARGV[0];
- my $outfile = "chkPath.out";
- my $date = `date`;
- print "the check path begin at $date";
- open OUT, ">$outfile";
- print OUT "$date";
- close OUT;
- #read the ip and start children process 讀入ip后發(fā)起子進程chkClient去連接然后檢查路徑
- while (<>)
- {
- my $hostname = $_;
- chomp $hostname;
- $pid = fork();
- unless ( $pid )
- {
- print "connect to $hostname ...\n";
- &chkClient($hostname, $username, $password);
- exit;
- }
- sleep 6;
- }
- #end 父進程結(jié)束
- print "*"x30 . "\n";
- print "\nall the request is send, please wait and check out file!\n";
- print "*"x30 . "\n";
- #sub to check the ssh client 檢查client的函數(shù)
- sub chkClient
- {
- my ($ip, $user, $pass) = @_;
- my $os = "NotAIX";
- my $chk = "unknown";
- my $disk, $path;
- my $ssh = Net::SSH::Expect->new (
- host => "$ip",
- password=> "$pass" ,
- user => "$user",
- raw_pty => 1
- );
- $ssh->timeout(5);
- $ssh->login(1) or die "can not login $!\n";
- my $uname = $ssh->exec("uname");
- if($uname =~ /AIX/is)
- {
- $os = "AIX";
- $chk = "good";
- $ssh->send("lsdev -Ccdisk");
- $disk = $ssh->read_all(15);
- $ssh->send("lspath");
- $path = $ssh->read_all(15);
- }
- $ssh->close();
- if ( $os eq "AIX" )
- {
- open IPOUT, ">$ip";
- print IPOUT "disk:\n$disk\n";
- print IPOUT "path:\n$path\n";
- close IPOUT;
- my @diskline = split /\n/,$disk;
- my @pathline = split /\n/,$path;
- for (@diskline)
- {
- if ( /(hdisk\d{1,3})\s.*$disktype.*/ )
- {
- my $disk = $1;
- my $val = grep(/Enabled\s+$disk\s/, @pathline);
- if ( $val < 2 )
- {
- $chk = "error";
- }
- print "$ip: $disk has enabled path $val: $chk\n";
- }
- }
- }
- open OUT, ">>$outfile";
- print OUT "$ip,$os,$chk\n";
- close OUT;
- print "*"x30;
- print "check $ip complete: os: $os, path check:$chk\n";
- }
復(fù)制代碼 PS:在linux安裝IO-Tty非常順利,但是在AIX上就不行,提示cc_r找不到,雖然查看是有c的編譯環(huán)境的
用了一個其他的辦法:
先安裝gcc,然后下載perl源碼,編譯時指定gcc
# ./Configure -des -Dcc=gcc -Dprefix=/opt/perl5.16.2
# make
# make install
同樣的方法進行安裝IO-Tty Expect Net::SSH::Expect最后將腳本的第一行改成
#!/opt/perl5.16.2/bin/perl
如何運行:
編輯一個文本文件,每個ip一行,然后將文件名作為參數(shù)運行腳本,會在屏幕上輸出每個ip對應(yīng)的磁盤的path數(shù)- connect to 10.190.41.117 ...
- connect to 10.200.157.179 ...
- connect to 10.200.157.139 ...
- connect to 10.200.150.109 ...
- connect to 10.200.134.99 ...
- connect to 10.200.122.9 ...
- 10.200.150.109: hdisk3 has enabled path 2: good
- 10.200.150.109: hdisk4 has enabled path 2: good
- 10.200.150.109: hdisk5 has enabled path 2: good
- 10.200.150.109: hdisk6 has enabled path 2: good
- 10.200.150.109: hdisk7 has enabled path 2: good
- 10.200.150.109: hdisk8 has enabled path 2: good
- 10.200.150.109: hdisk9 has enabled path 2: good
- 10.200.150.109: hdisk10 has enabled path 2: good
- 10.200.150.109: hdisk11 has enabled path 2: good
- 10.200.150.109: hdisk12 has enabled path 2: good
- 10.200.150.109: hdisk13 has enabled path 2: good
- 10.200.150.109: hdisk14 has enabled path 2: good
- 10.200.150.109: hdisk15 has enabled path 2: good
- ...
- 10.190.57.130: hdisk26 has enabled path 2: good
- 10.190.57.130: hdisk27 has enabled path 2: good
- ******************************check 10.190.57.130 complete: os: AIX, path check:good
- connect to 10.190.35.126 ...
- ******************************check 10.190.50.104 complete: os: AIX, path check:good
- ******************************check 10.190.34.94 complete: os: NotAIX, path check:unknown
- connect to 10.190.50.54 ...
- ******************************check 10.190.35.124 complete: os: NotAIX, path check:unknown
- connect to 10.190.57.34 ...
- 10.190.122.9: hdisk2 has enabled path 2: good
- 10.190.122.9: hdisk3 has enabled path 2: good
- 10.190.122.9: hdisk4 has enabled path 2: good
- 10.190.122.9: hdisk5 has enabled path 2: good
- 10.190.122.9: hdisk6 has enabled path 2: good
- 10.190.122.9: hdisk7 has enabled path 2: good
- 10.190.122.9: hdisk8 has enabled path 2: good
- ...
復(fù)制代碼 完成后會在當前目錄下生成chkPath.out- [user@storage]$ cat chkPath.out
- Mon Feb 25 10:14:14 CST 2013
- 10.190.121.84,NotAIX,unknown
- 10.190.121.85,NotAIX,unknown
- 10.190.121.87,NotAIX,unknown
- 10.190.35.44,AIX,good
- 10.190.35.45,AIX,good
- 10.190.57.35,AIX,good
- 10.190.57.137,AIX,good
- 10.190.57.101,NotAIX,unknown
- ...
復(fù)制代碼 同時如果是AIX系統(tǒng)的,還會生成以ip命名的單獨的文件,記錄lsdev和lspath的輸出- [jtwangxm@storage chkPath]$ cat 10.200.157.139
- disk:
- hdisk0 Available 07-08-00 SAS Disk Drive
- hdisk1 Available 07-08-00 SAS Disk Drive
- hdisk2 Available 02-00-02 3PAR InServ Virtual Volume
- hdisk3 Available 02-00-02 3PAR InServ Virtual Volume
- hdisk4 Available 02-00-02 3PAR InServ Virtual Volume
- hdisk5 Available 02-00-02 3PAR InServ Virtual Volume
- hdisk6 Available 02-00-02 3PAR InServ Virtual Volume
- hdisk7 Available 03-00-02 3PAR InServ Virtual Volume
- hdisk8 Available 03-00-02 3PAR InServ Virtual Volume
- hdisk9 Available 03-00-02 3PAR InServ Virtual Volume
- hdisk10 Available 03-00-02 3PAR InServ Virtual Volume
- hdisk11 Available 03-00-02 3PAR InServ Virtual Volume
- $
- path:
- Enabled hdisk0 sas0
- Enabled hdisk1 sas0
- Available ses0 sas0
- Available ses1 sas0
- Available ses2 sas1
- Enabled hdisk2 fscsi0
- Enabled hdisk3 fscsi0
- Enabled hdisk4 fscsi0
- Enabled hdisk5 fscsi0
- Enabled hdisk6 fscsi0
- Enabled hdisk2 fscsi2
- Enabled hdisk3 fscsi2
- Enabled hdisk4 fscsi2
- Enabled hdisk5 fscsi2
- ...
復(fù)制代碼 |
|