Windows Server端口监控之powershell脚本

创建文件:monotor.PS1,内容如下:

$s2="D:\WSIDC\后台服务0906\DataProcessSvr\DataProcessSvr.exe"
$s3="D:\WSIDC\后台服务0906\RealtimeSearchSvr\RealtimeSearchSvr.exe"
$Ipaddress='127.0.0.1'
$Port=5672

#探测端口
$t = New-Object Net.Sockets.TcpClient
try
{
$t.Connect($Ipaddress,$Port)
}
catch{}

#如果可以连接端口
if($t.Connected)
{ 
add-content "$log" "$(Get-Date): Port $Port is OK"
}
else
{
#连接断开,需要重连.
add-content "$log" "$(Get-Date): Port $Port is down"

#重启服务
get-service|ForEach-Object{if(($_.name -eq 'qpidd') -and $_.status -ne 'running'){start-service $_.name}}
add-content "$log" "$(Get-Date): qpidd has been restarted."
Start-Sleep -Seconds 3
Start-Process -FilePath "$s2"
add-content "$log" "$(Get-Date): $s2 has been restarted."
Start-Sleep -Seconds 3
Start-Process -FilePath "$s3"
add-content "$log" "$(Get-Date): $s3 has been restarted."
#stop-process -name nginx.exe -force
}

上一篇:ios授权登录sdk分享(不包含支付功能)


下一篇:分享10个 javascript 在线 debugging 工具