自己写的一个批量远程连接aix后检查lsdev里指定的磁盘类型和对应的lspath的数量,还挺好用,给大家分享一下,也请大家帮忙看看有什么地方需要改进的, 要先装IO-Tty,Expect,Net::SSH::Expect[user@storage]$ cat chkPath#!/usr/bin/perluse 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后发起子进程chkClient去连接然后检查路径while (){ my $hostname = $_; chomp $hostname; $pid = fork(); unless ( $pid ) { print "connect to $hostname ...\n"; &chkClient($hostname, $username, $password); exit; } sleep 6;}#end 父进程结束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的函数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 { $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";}复制代码PS:在linux安装IO-Tty非常顺利,但是在AIX上就不行,提示cc_r找不到,虽然查看是有c的编译环境的用了一个其他的办法:先安装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一行,然后将文件名作为参数运行脚本,会在屏幕上输出每个ip对应的磁盘的path数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: good10.200.150.109: hdisk4 has enabled path 2: good10.200.150.109: hdisk5 has enabled path 2: good10.200.150.109: hdisk6 has enabled path 2: good10.200.150.109: hdisk7 has enabled path 2: good10.200.150.109: hdisk8 has enabled path 2: good10.200.150.109: hdisk9 has enabled path 2: good10.200.150.109: hdisk10 has enabled path 2: good10.200.150.109: hdisk11 has enabled path 2: good10.200.150.109: hdisk12 has enabled path 2: good10.200.150.109: hdisk13 has enabled path 2: good10.200.150.109: hdisk14 has enabled path 2: good10.200.150.109: hdisk15 has enabled path 2: good...10.190.57.130: hdisk26 has enabled path 2: good10.190.57.130: hdisk27 has enabled path 2: good******************************check 10.190.57.130 complete: os: AIX, path check:goodconnect 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:unknownconnect to 10.190.50.54 ...******************************check 10.190.35.124 complete: os: NotAIX, path check:unknownconnect to 10.190.57.34 ...10.190.122.9: hdisk2 has enabled path 2: good10.190.122.9: hdisk3 has enabled path 2: good10.190.122.9: hdisk4 has enabled path 2: good10.190.122.9: hdisk5 has enabled path 2: good10.190.122.9: hdisk6 has enabled path 2: good10.190.122.9: hdisk7 has enabled path 2: good10.190.122.9: hdisk8 has enabled path 2: good...复制代码完成后会在当前目录下生成chkPath.out[user@storage]$ cat chkPath.outMon Feb 25 10:14:14 CST 201310.190.121.84,NotAIX,unknown10.190.121.85,NotAIX,unknown10.190.121.87,NotAIX,unknown10.190.35.44,AIX,good10.190.35.45,AIX,good10.190.57.35,AIX,good10.190.57.137,AIX,good10.190.57.101,NotAIX,unknown...复制代码同时如果是AIX系统的,还会生成以ip命名的单独的文件,记录lsdev和lspath的输出[jtwangxm@storage chkPath]$ cat 10.200.157.139disk:hdisk0 Available 07-08-00 SAS Disk Drivehdisk1 Available 07-08-00 SAS Disk Drivehdisk2 Available 02-00-02 3PAR InServ Virtual Volumehdisk3 Available 02-00-02 3PAR InServ Virtual Volumehdisk4 Available 02-00-02 3PAR InServ Virtual Volumehdisk5 Available 02-00-02 3PAR InServ Virtual Volumehdisk6 Available 02-00-02 3PAR InServ Virtual Volumehdisk7 Available 03-00-02 3PAR InServ Virtual Volumehdisk8 Available 03-00-02 3PAR InServ Virtual Volumehdisk9 Available 03-00-02 3PAR InServ Virtual Volumehdisk10 Available 03-00-02 3PAR InServ Virtual Volumehdisk11 Available 03-00-02 3PAR InServ Virtual Volume$ path:Enabled hdisk0 sas0Enabled hdisk1 sas0Available ses0 sas0Available ses1 sas0Available ses2 sas1Enabled hdisk2 fscsi0Enabled hdisk3 fscsi0Enabled hdisk4 fscsi0Enabled hdisk5 fscsi0Enabled hdisk6 fscsi0Enabled hdisk2 fscsi2Enabled hdisk3 fscsi2Enabled hdisk4 fscsi2Enabled hdisk5 fscsi2...复制代码 10-09 23:24