亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2086 | 回復(fù): 2
打印 上一主題 下一主題

自己寫的檢查lspath的腳本 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2013-02-26 09:13 |只看該作者 |倒序瀏覽
本帖最后由 wxm8000 于 2013-02-26 13:16 編輯

自己寫的一個批量遠程連接aix后檢查lsdev里指定的磁盤類型和對應(yīng)的lspath的數(shù)量,還挺好用,給大家分享一下,也請大家?guī)兔纯从惺裁吹胤叫枰倪M的,:wink:

要先裝IO-Tty,Expect,Net::SSH::Expect
  1. [user@storage]$ cat chkPath
  2. #!/usr/bin/perl
  3. use Net::SSH::Expect;

  4. my $username = "user";
  5. my $password = "password";

  6. #檢查的磁盤類型為3PAR,如果是其他類型的可以在這里修改,比如XP等
  7. my $disktype = "3PAR";

  8. my $pid = 1;

  9. die "please give a filename for the ip list!\n" if @ARGV ne 1;
  10. die "please give a true file for the ip list!\n" if ! -f $ARGV[0];

  11. my $outfile = "chkPath.out";
  12. my $date = `date`;
  13. print "the check path begin at $date";

  14. open OUT, ">$outfile";
  15. print OUT "$date";
  16. close OUT;

  17. #read the ip and start children process 讀入ip后發(fā)起子進程chkClient去連接然后檢查路徑
  18. while (<>)
  19. {
  20.         my $hostname = $_;
  21.         chomp $hostname;
  22.         $pid = fork();
  23.         unless ( $pid )
  24.         {
  25.                 print "connect to $hostname  ...\n";
  26.                 &chkClient($hostname, $username, $password);
  27.                 exit;
  28.         }
  29.         sleep 6;
  30. }

  31. #end 父進程結(jié)束
  32. print "*"x30 . "\n";
  33. print "\nall the request is send, please wait and check out file!\n";
  34. print "*"x30 . "\n";

  35. #sub to check the ssh client 檢查client的函數(shù)
  36. sub chkClient
  37. {
  38.         my ($ip, $user, $pass) = @_;
  39.         my $os = "NotAIX";
  40.         my $chk = "unknown";
  41.         my $disk, $path;
  42.         my $ssh = Net::SSH::Expect->new (
  43.                    host => "$ip",
  44.                    password=> "$pass" ,
  45.                    user => "$user",
  46.                    raw_pty => 1
  47.                );
  48.         $ssh->timeout(5);
  49.         $ssh->login(1) or die "can not login $!\n";
  50.         my $uname = $ssh->exec("uname");
  51.         if($uname =~ /AIX/is)
  52.         {
  53.                 $os = "AIX";
  54.                 $chk = "good";
  55.                 $ssh->send("lsdev -Ccdisk");
  56.                 $disk = $ssh->read_all(15);
  57.                 $ssh->send("lspath");
  58.                 $path = $ssh->read_all(15);
  59.         }

  60.         $ssh->close();

  61.         if ( $os eq "AIX" )
  62.         {
  63.                                 open IPOUT, ">$ip";
  64.                 print IPOUT "disk:\n$disk\n";
  65.                 print IPOUT "path:\n$path\n";
  66.                 close IPOUT;

  67.                 my @diskline = split /\n/,$disk;
  68.                 my @pathline = split /\n/,$path;
  69.                 for (@diskline)
  70.                 {
  71.                         if ( /(hdisk\d{1,3})\s.*$disktype.*/ )
  72.                         {
  73.                                 my $disk = $1;
  74.                                 my $val = grep(/Enabled\s+$disk\s/, @pathline);
  75.                                 if ( $val < 2 )
  76.                                 {
  77.                                         $chk = "error";
  78.                                 }
  79.                                 print "$ip: $disk has enabled path $val: $chk\n";
  80.                         }
  81.                 }
  82.         }

  83.         open OUT, ">>$outfile";
  84.         print OUT "$ip,$os,$chk\n";
  85.         close OUT;
  86.         print "*"x30;
  87.         print "check $ip complete: os: $os, path check:$chk\n";

  88. }
復(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ù)
  1. connect to 10.190.41.117  ...
  2. connect to 10.200.157.179  ...
  3. connect to 10.200.157.139  ...
  4. connect to 10.200.150.109  ...
  5. connect to 10.200.134.99  ...
  6. connect to 10.200.122.9  ...
  7. 10.200.150.109: hdisk3 has enabled path 2: good
  8. 10.200.150.109: hdisk4 has enabled path 2: good
  9. 10.200.150.109: hdisk5 has enabled path 2: good
  10. 10.200.150.109: hdisk6 has enabled path 2: good
  11. 10.200.150.109: hdisk7 has enabled path 2: good
  12. 10.200.150.109: hdisk8 has enabled path 2: good
  13. 10.200.150.109: hdisk9 has enabled path 2: good
  14. 10.200.150.109: hdisk10 has enabled path 2: good
  15. 10.200.150.109: hdisk11 has enabled path 2: good
  16. 10.200.150.109: hdisk12 has enabled path 2: good
  17. 10.200.150.109: hdisk13 has enabled path 2: good
  18. 10.200.150.109: hdisk14 has enabled path 2: good
  19. 10.200.150.109: hdisk15 has enabled path 2: good
  20. ...
  21. 10.190.57.130: hdisk26 has enabled path 2: good
  22. 10.190.57.130: hdisk27 has enabled path 2: good
  23. ******************************check 10.190.57.130 complete: os: AIX, path check:good
  24. connect to 10.190.35.126  ...
  25. ******************************check 10.190.50.104 complete: os: AIX, path check:good
  26. ******************************check 10.190.34.94 complete: os: NotAIX, path check:unknown
  27. connect to 10.190.50.54  ...
  28. ******************************check 10.190.35.124 complete: os: NotAIX, path check:unknown
  29. connect to 10.190.57.34  ...
  30. 10.190.122.9: hdisk2 has enabled path 2: good
  31. 10.190.122.9: hdisk3 has enabled path 2: good
  32. 10.190.122.9: hdisk4 has enabled path 2: good
  33. 10.190.122.9: hdisk5 has enabled path 2: good
  34. 10.190.122.9: hdisk6 has enabled path 2: good
  35. 10.190.122.9: hdisk7 has enabled path 2: good
  36. 10.190.122.9: hdisk8 has enabled path 2: good
  37. ...
復(fù)制代碼
完成后會在當前目錄下生成chkPath.out
  1. [user@storage]$ cat chkPath.out
  2. Mon Feb 25 10:14:14 CST 2013
  3. 10.190.121.84,NotAIX,unknown
  4. 10.190.121.85,NotAIX,unknown
  5. 10.190.121.87,NotAIX,unknown
  6. 10.190.35.44,AIX,good
  7. 10.190.35.45,AIX,good
  8. 10.190.57.35,AIX,good
  9. 10.190.57.137,AIX,good
  10. 10.190.57.101,NotAIX,unknown
  11. ...
復(fù)制代碼
同時如果是AIX系統(tǒng)的,還會生成以ip命名的單獨的文件,記錄lsdev和lspath的輸出
  1. [jtwangxm@storage chkPath]$ cat 10.200.157.139
  2. disk:
  3. hdisk0  Available 07-08-00 SAS Disk Drive
  4. hdisk1  Available 07-08-00 SAS Disk Drive
  5. hdisk2  Available 02-00-02 3PAR InServ Virtual Volume
  6. hdisk3  Available 02-00-02 3PAR InServ Virtual Volume
  7. hdisk4  Available 02-00-02 3PAR InServ Virtual Volume
  8. hdisk5  Available 02-00-02 3PAR InServ Virtual Volume
  9. hdisk6  Available 02-00-02 3PAR InServ Virtual Volume
  10. hdisk7  Available 03-00-02 3PAR InServ Virtual Volume
  11. hdisk8  Available 03-00-02 3PAR InServ Virtual Volume
  12. hdisk9  Available 03-00-02 3PAR InServ Virtual Volume
  13. hdisk10 Available 03-00-02 3PAR InServ Virtual Volume
  14. hdisk11 Available 03-00-02 3PAR InServ Virtual Volume
  15. $
  16. path:
  17. Enabled   hdisk0  sas0
  18. Enabled   hdisk1  sas0
  19. Available ses0    sas0
  20. Available ses1    sas0
  21. Available ses2    sas1
  22. Enabled   hdisk2  fscsi0
  23. Enabled   hdisk3  fscsi0
  24. Enabled   hdisk4  fscsi0
  25. Enabled   hdisk5  fscsi0
  26. Enabled   hdisk6  fscsi0
  27. Enabled   hdisk2  fscsi2
  28. Enabled   hdisk3  fscsi2
  29. Enabled   hdisk4  fscsi2
  30. Enabled   hdisk5  fscsi2
  31. ...
復(fù)制代碼

論壇徽章:
0
2 [報告]
發(fā)表于 2013-02-26 11:29 |只看該作者
能提供一個你運行這個程序后的輸出么?呵呵

論壇徽章:
0
3 [報告]
發(fā)表于 2013-02-26 13:17 |只看該作者
回復(fù) 2# ts99


    已經(jīng)添加了輸出效果
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP