用Loop测试连接 [英] Test Connection with Loop

查看:185
本文介绍了用Loop测试连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要PowerShell脚本来测试连接(ICMP) 每隔10分钟,如果计算机没有响应,它将立即向我的电子邮件发送电子邮件,主题为"您的服务器已关闭"。 。当计算机恢复并做出响应时, 
将通过subjet"您的服务器已启动"对我进行通知。 并将继续检查。

i need powershell script which will test connection (ICMP)  every 10-minute, if computer is not responding it will immediately send email to my email with subject "Your Server is Down" . and when computer will restored and respond,  it will notificate me with subjet "Your Server is Up"  and will continue to check.

--------

function test_ping

{

尝试

{

写主机"连接断开"&b
do {$ test = Test-Connection -ComputerName myphone。 ghc.com -ErrorAction:停止}

直到  ($ test.replysize -lt 0)

}

catch

{

发送¥ b $ b写主机"连接已断开"

}



}



函数发送

{

send-mailmessage -to" rufat" -from"reporr< report01@example.com>" -subject" report sender" -SmtpServer 192.168.1.x

Start-Sleep -s 300

test_ping

}

function test_ping
{
try
{
Write-Host "Connection has broken"
do {$test = Test-Connection -ComputerName myphone.ghc.com -ErrorAction:Stop}
until  ($test.replysize -lt 0)
}
catch
{
send
Write-Host "Connection has broken"
}

}

function send
{
send-mailmessage -to "rufat" -from "reporr <report01@example.com>" -subject "report sender" -SmtpServer 192.168.1.x
Start-Sleep -s 300
test_ping
}

----------

----------

我是Powershell世界的初学者。并尝试写这样的类似..但我需要帮助纠正我的脚本  ALSO&NBSP;请告诉我,你得到的地方  "想象与幻想" 什么时候开始 从一开始 
写一些脚本? 我想知道逻辑方式..

i am beginner in Powershell world. and had try to write similar like this .. but i need help with correcting my script  ALSO  please advice me , where you get  "imagination and fantasy"  when you start  from beginning  write some script ?  i want to know logic way..

感谢您的建议..

推荐答案

我建议使用监控工具进行关键生产环境

I advice to use the monitorig tool for Critical Production enviornment

但是你可以使用这个脚本

However you can use this script

使用PowerShell Ping多个服务器并通过电子邮件发送输出 - v2

根据需要在任务计划程序中安排它。

Schedule it in Task Scheduler as required.


这篇关于用Loop测试连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆