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 ...
随机推荐
- yii2之GridView小部件
GridView小部件用于展示多条数据的列表.GridView小部件的使用需要数据提供器即yii\data\ActiveDataProvider的实例作为参数,所以 第一步就是要在控制器方法中创建这个 ...
- LeetCode 695. Max Area of Island (岛的最大区域)
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- LeetCode 121. Best Time to Buy and Sell Stock (买卖股票的最好时机)
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- NLog在asp.net中的使用
一.关于安装 1.可以直接通过vs自带的Nuget包管理器来搜索下载,直接搜索"NLog": 注意,除了要安装第一个之外,一定要安装"NLog.Config", ...
- django-rest-framework之序列化
前言:昨天学习了rest-framework序列化方面的知识,故写了博客记录一下.官网:http://www.django-rest-framework.org/tutorial/1-serializ ...
- linux学习(八)chmod、chown、umask、lsattr、chattr
一.权限位 权限位分为两个部分,第一个部分是谁的权限,第二部分是权限是多少.其中第一个部分一般分为:用户,用户组,其他用户.第二部分分为r:读权限,w:写权限,x:执行权限.可读,可写,可执行的权限, ...
- Javascript中的Trait与代码重用
Javascript中的Trait与代码重用 来源 http://www.ituring.com.cn/article/64103 我们知道,OOP中最普遍的代码重用方式是通过继承,但是,继承有一些缺 ...
- [Bayesian] “我是bayesian我怕谁”系列 - Markov and Hidden Markov Models
循序渐进的学习步骤是: Markov Chain --> Hidden Markov Chain --> Kalman Filter --> Particle Filter Mark ...
- linux 安装wordpress 无故往外发送大量垃圾邮件
linux 安装wordpress 无故往外发送大量垃圾邮件 始末 表现出来的现象就是, 网站运行没多久,mysql服务就挂了,重启也无法启动起来,提示 No such file or dicrion ...
- 添加无登录权限的SSH用户命令
useradd -M -s /sbin/nologin -n username passwd username userdel -r username