powershell 监控, 重启网卡
#powershell 监控, 重启网卡
一台Windows服务器,由于负荷较大,偶尔会网络中断,就写了个powershell脚本,监控ip是否通,不通就重启网卡
cls
$host.UI.RawUI.WindowTitle = ‘……VM监控……’
$host.UI.RawUI.ForegroundColor='Green'
#version V1.3.9
#t1间隔时间s
$t1=5
$log='C:\Router.log.txt'
#region
$nu=0
$n1="##########"
$n2="监控总次数"
$cq1=0
$cq2=0
$ip1='192.168.0.1'
$ip2='172.16.11.145'
$ip3='172.16.11.8'
#endregion
if(Test-Path $log){}else
{
"初始化log"
echo $n1 >$log
echo $n2 >>$log
echo $nu >>$log
echo $n1 >>$log
}
while(1 -lt 2)
{
sleep $t1
cls
$log1=Get-Content $log
$nu=$log1[2]
$nu=[int]$nu + 1
echo $n1
echo "$($n2):$($nu)"
echo "监控间隔:$($t1)s"
echo "重启网卡:$($cq1)"
echo "重启路由:$($cq2)"
echo $n1
#write
echo $n1 >$log
echo $n2 >>$log
echo $nu >>$log
echo $log1[3..($log1.count-1)] >>$log #check
if ((Get-WmiObject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip1'").StatusCode -eq 0)
{
"The router is online!"
#检测内网
if ((Get-WmiObject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip2'").StatusCode -eq 0)
{ "The Lan is online!" }
elseif ((Get-WmiObject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip3'").StatusCode -eq 0)
{ "The Lan is online!" }
else
{
"重启内网网卡"
$cq1=$cq1 + 1
echo "重启内网网卡, $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ffff')">>$log
Get-NetAdapter -Name '本地连接' | Restart-NetAdapter
Get-NetAdapter -Name 'Lan' | Restart-NetAdapter
sleep 30
}
}
else
{
"The router is offline!"
"重启路由网卡"
$cq1=$cq1 + 1
echo "重启路由网卡, $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ffff')">>$log
Get-NetAdapter -Name 'Wan2' | Restart-NetAdapter
Get-NetAdapter -Name 'Lan2' | Restart-NetAdapter
sleep 30
#再次检测
if ((Get-WmiObject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip1'").StatusCode -eq 0)
{ "The route is online!" }
else
{
"重启 router"
$cq2=$cq2 + 1
echo "重启 router, $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ffff')">>$log
$vname='ikuai-router'
Restart-VM $vname -Force
sleep 100
}
}
}
powershell 监控, 重启网卡的更多相关文章
- shell监控网卡状态,故障时自动重启网卡
今天朋友找我写个监控网卡状态的脚本,要求在系统网卡挂了可以自己启动起来,这个要求是不是很bt,我考虑了半天,简单的写了个shell脚本来监控,实现原理是使用ping来测试网络连通性,如果不通就重启 ...
- [AlwaysOn Availability Groups]使用Powershell监控AlwayOn健康
使用Powershell监控AlwayOn健康 1.基本命令概述 AlwayOn Dashboard是很有用的查看整体AG健康状况的工具.但是这个工具不是用于7*24监控的.如果应用程序夜间发送严重的 ...
- Linux:Vmware安装linux虚拟机,桥接方式配置静态IP后重启网卡,提示:Error,some other host already uses address 10.252.252.21...
问题: Vmware安装linux虚拟机,桥接方式配置静态IP后重启网卡,提示:Error,some other host already uses address 10.252.252.21... ...
- 【转】ubuntu 重启命令,ubuntu 重启网卡方法
ubuntu 重启命令 重启命令:1.reboot2.shutdown -r now 立刻重启(root用户使用)3.shutdown -r 10 过10分钟自动重启(root用户使用)4.shutd ...
- ubuntu 重启命令,ubuntu 重启网卡方法
ubuntu 重启命令 重启命令:1.reboot2.shutdown -r now 立刻重启(root用户使用)3.shutdown -r 10 过10分钟自动重启(root用户使用)4.shutd ...
- 重启网卡报错:Device eth0 does not seem to be present
ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: service network restartShutting down loopback insterface: ...
- 在VMware的虚拟机中克隆CentOS,在重启网卡的时候报错解决办法
克隆虚拟机配置 1.修改:vi /etc/hosts 2.修改:vi /etc/sysconfig/network 3.重启生效:reboot或者init 6 如不重启可以输入:hostname 新 ...
- Linux 重启网卡失败 Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
linux下重启网卡使用命令 : service network restart 时报错: [root@slave01 hadoop]# service network restart Startin ...
- Ubuntu重启网卡的三种方法
一.network利用root帐户# service network restart 或者/etc/init.d/networking restart 二.ifdown/ifup# ifdown et ...
随机推荐
- Mybatis基本用法--下
Mybatis基本用法--下 第七部分 mybatis-spring-boot-starter 官网:http://www.mybatis.org/spring-boot-starter/mybati ...
- LeetCode 448. Find All Numbers Disappeared in an Array (在数组中找到没有出现的数字)
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
- Spring-SpringMVC-Mybatis整合的步骤
1.导入jar包 1.1 spring面向切面jar包 com.springsource.net.sf.cglib-2.2.0.jar com.springsource.org.aopallianc ...
- .2-Vue源码起步(2)
接着第一节开始继续吧(GoGoGo) 上一节把mergeOptions函数弄完了,最后返回一个options赋给了vm.$options. 这一节继续跑代码: function initMixin(V ...
- Ubuntu上64位adv无法创建问题
Ubuntu上安装android开发环境,前面都成功了,但到了最后创建adv的时候却总是失败. 出现了这个问题.最后,上网找了这个教程http://blog.sina.com.cn/s/blog_66 ...
- 走进 Visual Studio Mobile Center for Xamarin.Forms
前几篇分别介绍了 Xamarin.Forms 的 MVVM 的 Prism,UITest,Nuint Test,那这样算下来,代码部分基本结构都有了(逻辑就先忽略吧) 那接下来就应该是自动 Build ...
- 借助csv用PHP生成excel文件
当你将xml文件改为csv后缀会发现原先的表格结构都变成用逗号隔开的一行一行数据,就像这样 编号,姓名,年龄 001,王宇,28 002,刘三,20 由此看来,如果能将PHP数据输出为这样的格式,然后 ...
- Catch him
Problem Description 在美式足球中,四分卫负责指挥整只球队的进攻战术和跑位,以及给接球员传球的任务.四分卫是一只球队进攻组最重要的球员,而且一般身体都相对比较弱小,所以通常球队会安排 ...
- 暑假练习赛 006 E Vanya and Label(数学)
Vanya and LabelCrawling in process... Crawling failed Time Limit:1000MS Memory Limit:262144KB ...
- solr安装血泪史
Windows10专业版,solr6.5.1,tomcat8.5.14,jdk1.8 转自http://www.jianshu.com/p/dd7a59b3f0b5 科普篇 来自百度百科:Solr简介 ...