perl实现检测服务器中的服务是否正常脚本分享
作者:junjie 时间:2022-05-05 21:17:12
程序调用远端服务,为了确保可用性最好在使用前进行健康检测,将异常的服务排除。
#!/usr/bin/perl
#
use strict;
use IO::Socket;
my @servers;
$servers[0]=['180.153.100.93',2222];
$servers[1]=['180.153.100.93',22];
$servers[2]=['180.153.100.93',80];
my $i=0;
my $interval=3;
my $count=int(60/$interval);
while($i < $count){
foreach (@servers){
if(fetch_server_status(@$_)){
print $$_[0] . ':' . $$_[1] ."ok\n";
}else{
print $$_[0] . ':' . $$_[1] ."bad\n";
}
}
$i++;
sleep $interval;
}
sub fetch_server_status(){
my($ip,$port)=@_;
my $socket=IO::Socket::INET->new(
PeerAddr => $ip,
PeerPort => $port,
Timeout => 1,
);
if(!$socket){
return 0;
}else{
return 1;
}
$socket->close;
}
标签:perl,检测服务器
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 函数内部修改外部变量的方法
2022-05-24 09:04:19
关于Python网络爬虫requests库的介绍
2021-10-20 23:13:52
10 个Python中Pip的使用技巧分享
2023-08-02 17:52:45
基于Python制作一个文件解压缩工具
2021-01-10 08:00:13
![](https://img.aspxhome.com/file/2023/0/67410_0s.png)
windows+vscode安装paddleOCR运行环境的步骤
2021-05-09 06:12:26
![](https://img.aspxhome.com/file/2023/9/134829_0s.png)
python实践项目之监控当前联网状态详情
2022-06-05 02:02:57
![](https://img.aspxhome.com/file/2023/8/133248_0s.jpg)
php中运用http调用的GET和POST方法示例
2023-11-23 02:39:35
阿里云 CentOS7.4 安装 Python3.6的方法讲解
2022-06-12 23:56:13
python+unittest+requests实现接口自动化的方法
2022-04-10 08:47:38
![](https://img.aspxhome.com/file/2023/3/65123_0s.png)
Python猴子补丁Monkey Patch用法实例解析
2022-02-20 06:45:01
python数据处理详情
2021-05-08 12:53:12
![](https://img.aspxhome.com/file/2023/6/112436_0s.png)
Python实现读取TXT文件数据并存进内置数据库SQLite3的方法
2021-03-01 14:14:27
web.py 十分钟创建简易博客实现代码
2022-10-23 00:55:38
python输出电脑上所有的串口名的方法
2022-06-23 20:56:03
![](https://img.aspxhome.com/file/2023/2/112732_0s.jpg)
如何编写一个基于WEB的文件查询系统?
2009-11-08 18:55:00
天气预报调用代码
2008-11-18 15:59:00
![](https://img.aspxhome.com/file/UploadPic/200811/18/g20081115162112-94s.jpg)
Silverlight与Flash的技术比较
2009-04-19 18:45:00
互联网一家之言(一):叫用户为你买单
2009-06-09 11:32:00
![](https://img.aspxhome.com/file/UploadPic/20096/9/qqe688aae59bbee69caae591bde5908d1-49s.jpg)
python获取指定字符串中重复模式最高的字符串方法
2021-03-25 14:59:25
Python xlwings插入Excel图片的实现方法
2023-11-23 05:53:18
![](https://img.aspxhome.com/file/2023/8/115738_0s.jpg)