使用PowerShell将数据域数据提取到SSH

时间:2016-06-23 21:54:14

标签: powershell ssh emc

我目前正在开发一个Powershell脚本,该脚本将在服务器上运行,并且每周/每月ssh到数据域的文本列表。从该列表中,它将遍历每个,连接并运行命令以从每个DD获取信息。我之前没有使用Powershell的经验,而且我的知识仅限于大学教育级别的Linux和标准命令。

该脚本基于以下内容:

  

http://findnevilleat.blogspot.ca/2013/12/using-powershell-to-check-data-domains.html

我目前正在尝试修改脚本以满足我的需求,但一直停留在输出上。 目前我可以进入每个数据域并使用“df”和post-comp取出数据但是抓住其他数据对我来说仍然是一个谜。(甚至在EMC网站上也没有很多来源)。

总结一下,我想知道是否有人知道如何从以下命令中获取更多信息:

  • system - show all / show modelno / show hardware / show stats
  • filesys - 显示空间

到目前为止,这是我的脚本的基本概述:(我为这个烂摊子道歉,我只能做很多编辑)

          WriteLog "Checking Data Domain Available Space"
          $includeList="Cleanable GiB|--------|/data: post-comp" #Data domain format command to print
          $DB = Get-Content $answerfile #inputstream from file


          foreach ($Data in $DB){ ##bracket required on same line for foreach / foreach for iteration through data domains
              $hostname = $Data.Trim() #gets host name without new line character for the SSH command.

                #~~~~~~~~~ Password Set up ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                if($hostname -eq "139.12.34.56" -Or $hostname -eq 
 "10.123.11.108") ##if hostname is one of the selected, change password
 to correct 
                {
                $passwd = "12345PASS"
                }
                else #all other servers require this secondary password
                {
                $passwd = "54321PASS" 
                }
                #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                # Options: Hardcoded(current) / Read write from file.
                # With more passwords: Hardcoded = Switch
                #                      ReadWrite = Add to list


                #~~~~~~~~~~  SSH command and exe command Set up Process~~~~~~~~~~~~~~~~~
                $exe = "CMD" #Launch CMD for use


              $command = "/C $plinkcommand $user@$Data -pw ""$passwd"" df" #ssh command
              $Data > 
                #$command2 = "/C $plinkcommand $user@$Data -pw ""$passwd"" System show preformance" #ETC
                #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                # Currently supporting structure(below) to run other commands
                # Commands to be added: System  - (show all, show modelno, show compression, show hardware, show stats)    
                #                       Filesys - Show space
                #                       Possibly more to be added at a later time


                #~~~~~~~~~~~~~ Navigation of directories in host computer ~~~~~~~~~~~~~~
                invoke-expression "cd /" #Change directory to Root          
                invoke-expression "cd /users/kevindong/documents/powershellscripts" #change directory to
                plink location
                #Set up command to navigate to plink (requires set up dependedant on computer)
                #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                # Possible update to "invoke-expression", and possible specific targeted location of operating file directory

                #~~~~~~~~~~~~~ Execution of SSH data grab commands ~~~~~~~~~~~~~~~~~~~~~

              $outputcontents = &$exe $command ##ssh connect execution + "df" command

              if ($outputcontents -ne "") #if SSH is not null
              {

                  $outputcontents | ForEach-Object { #foreach requires bracket on same line
                       if ($_ -match $includeList) { WriteLog $_ }  #run data collection

                    #add commands here and write log them    
                    }
              }
                #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          }

感谢所有采取/调查我的问题的人。我很感激。

0 个答案:

没有答案