perl实现检测服务器中的服务是否正常脚本分享
程序调用远端服务,为了确保可用性最好在使用前进行健康检测,将异常的服务排除。
#!/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] ."okn";
}else{
print $$_[0] . ':' . $$_[1] ."badn";
}
}
$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操作MongoDB报错undefined symbol: HeUTF8解决方法
因为shell操作mongo比较麻烦,只好尝试使用perl操作mongo,perl需要操作mongodb必须先安装相应的驱动,大部分人使用cpan安装,个人觉得太麻烦,使用cpanm安装p
cpanm安装及Perl模块安装教程
cpanm是安装Perl模块的最方便的方法。自动下载安装依赖包。使用CPANshell或下载源码包安装模块,遇到大量依赖关系,非常头痛。下面就是一例:安装Mongo
Windows和Linux系统下perl连接SQL Server数据库的方法
本文将提供一些perl连接MicrosoftSQLServer数据库的实例。perl脚本运行在Windows和Linux平台。Windows平台如果在Windows平台下运行perl脚本,建议使用依赖DBI的两个
标签:操作,模块,平台,脚本,麻烦