第一个powershell脚本

#write-host "hello world“

#declare the txt we may seek from

$dir="E:\wget\sureProbe"

$probsumA="probesummary_A.txt"

$probsumB="probesummary_B.txt"

$probsumTR="probesummary_TR.txt"



$return_status=@{ "OK"="0";"WARNING"="1";"CRITICAL"="2";"UNKNOWN"="3" }


#declare the grep function

function grep_failed_sites

{

    param([string]$keyword)

    $stream = $input | Out-String -Stream

    $stream | Select-String $keyword

}


#get the failed_sites and put it into list

$sumA_res=$(cat $dir\$probsumA | grep_failed_sites ".TXT: 0")


$lengthA=$sumA_res.length


$return_value=""


#judge wether there is failed sites in txt

if ( $lengthA -eq 0 )

{

Write-Host "OK--All sites are OK!"

return $return_status["OK"]

}

elseif ( $lengthA -ge 1 )

{

foreach ($i in $sumA_res)

{

#Write-Host $i

$pooltmp=$i.toString().split("\")

$pool=$pooltmp[0].split(" ")[1]

$sitestmp=$i.toString().split("_")

$sitetp=$sitestmp[2].split(":")[0]

$site=$sitetp.split(".")[0].ToLower()

#Write-Host "pool:"$pool" site:"$site

$return_value=$return_value+"< Pool:"+$pool+" Site:"+$site+" >"

}

Write-Host "Critical--$lengthA sites down.<$return_value>"

return $return_status["CRITICAL"]

}

else

{

Write-Host "UNKNOWN--exception unknown"

return $return_status["UNKNOWN"]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值