2012-05-01 18 views

答えて

2

PowerShellのftpモジュールhereがあります。

0
$DEBUG = 1 
# Machines 
    $MachineNames = @("machine1","machine2") 
    $MachineIPs = @("192.168.1.1","192.168.1.2" ) 
# Websites 
    $WebsiteNames = @("website1","website2") 
    $WebsiteURLs = @("http://yahoo.com","http://google.com" ) 

#====== check websites 
$i = 0; 
foreach ($WebsiteURL in $WebsiteURLs){ 
    # First we create the request. 
    $HTTP_Request = [System.Net.WebRequest]::Create($WebsiteURL) 
    # We then get a response from the site. 
    $HTTP_Response = $HTTP_Request.GetResponse() 
    # We then get the HTTP code as an integer. 
    $HTTP_Status = [int]$HTTP_Response.StatusCode 
    #$HTTP_Response 
    If ($HTTP_Status -eq 200) { 
     if ($DEBUG -eq 1) {Write-Host "== " $WebsiteNames[$i] " is OK!" } 
    } 
    Else { 
     if ($DEBUG -eq 1) {Write-Host "==Error: "$WebsiteNames[$i] " may be down!" } 
     SendEmails $WebsiteNames[$i] 
    } 
    # Finally, we clean up the http request by closing it. 
    $HTTP_Response.Close() 
    Clear-Variable HTTP_Response 
    $i = $i + 1 
} 

#====== check IP 
$i = 0; 
foreach ($MachineIP in $MachineIPs){ 
    $isValidIP = Test-Connection $MachineIP -Count 1 -Quiet 
    if ($DEBUG -eq 1) { 
    $hostn = [System.Net.Dns]::GetHostEntry($MachineIP).HostName 
    New-Object -TypeName PSObject -Property @{'Host'=$hostn;'IP'=$MachineIP} 
    } 
    if (-not($isValidIP)) { 
     if ($DEBUG -eq 1) {Write-Host "==Error: " $MachineNames[$i] " ("$MachineIPs[$i]") may be down!" } 
     SendEmails $MachineNames[$i] 
    } 
    $i = $i + 1 
} 
関連する問題