perl检测网站首页状态
2011-05-26 10:20
357 查看
perl检测网站首页状态代码,随便写的,一起交流
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use Net::SMTP;
use POSIX qw/strftime/;
print <<EOF;
+--------------------------------------+
+----made by Henry He on 2011/03/03----+
+--------------------------------------+
EOF
my @array = ();
my $count = 0;
open FILE,'<','url.txt' or die "$!\n";
while (<FILE>) {
chomp;
/(\S+)/;
push @array,$1;
}
close FILE;
foreach my $url (@array) {
$count++;
my $obj = LWP::UserAgent->new(
keep_alive=>1,
timeout=>60);
my $req = HTTP::Request->new(GET=>"$url");
my $res = $obj->request($req);
if ($res->is_success) {
print $url,"\t",$res->status_line,"\n";
} else {
print "$url\tFailed:\t",$res->status_line,"\n";
sendemail("$url\tFailed:\t" . $res->status_line,"\n");
}
}
my $cur_time = strftime "%Y-%m-%d",localtime;
print "\n";
print <<EOF;
+-------------------------------------+
+ Finished check $count urls +
+-------------------------------------+
EOF
printlog("finished check $count urls at $cur_time...\n");
sub sendemail {
my $content = shift;
#change it for your smtp server
my $host = 'smtp.163.com';
#your email account here
my $mail_from = 'your_email_account';
#change it what you want to send here
my $mail_to = 'abc@abc.com';
#email subject
my $subject = 'Error Notice';
my $smtp = Net::SMTP->new($host,
Hello=>'localhost',
Timeout=>120,
Debug=>1
);
# modify it with your email username and password
$smtp->auth('your_email_username','your_email_password');
$smtp->mail($mail_from);
$smtp->to($mail_to);
$smtp->data();
$smtp->datasend("To: $mail_to\n");
$smtp->datasend("From: $mail_from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
$smtp->datasend("$content\n\n");
$smtp->dataend();
$smtp->quit;
}
sub printlog {
my $str = shift;
open LOG,'>>','check_url_status.log' or die "$!\n";
print LOG "$str";
close LOG;
}
url.txt
code: http://www.abc.com http://www.test.com http://www.xyz.com …………………………
…………………………
………………………… http://www.def.com http://www.123.com
本文出自 “BSDerの” 博客,请务必保留此出处http://hellosa.blog.51cto.com/2698675/505781
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use Net::SMTP;
use POSIX qw/strftime/;
print <<EOF;
+--------------------------------------+
+----made by Henry He on 2011/03/03----+
+--------------------------------------+
EOF
my @array = ();
my $count = 0;
open FILE,'<','url.txt' or die "$!\n";
while (<FILE>) {
chomp;
/(\S+)/;
push @array,$1;
}
close FILE;
foreach my $url (@array) {
$count++;
my $obj = LWP::UserAgent->new(
keep_alive=>1,
timeout=>60);
my $req = HTTP::Request->new(GET=>"$url");
my $res = $obj->request($req);
if ($res->is_success) {
print $url,"\t",$res->status_line,"\n";
} else {
print "$url\tFailed:\t",$res->status_line,"\n";
sendemail("$url\tFailed:\t" . $res->status_line,"\n");
}
}
my $cur_time = strftime "%Y-%m-%d",localtime;
print "\n";
print <<EOF;
+-------------------------------------+
+ Finished check $count urls +
+-------------------------------------+
EOF
printlog("finished check $count urls at $cur_time...\n");
sub sendemail {
my $content = shift;
#change it for your smtp server
my $host = 'smtp.163.com';
#your email account here
my $mail_from = 'your_email_account';
#change it what you want to send here
my $mail_to = 'abc@abc.com';
#email subject
my $subject = 'Error Notice';
my $smtp = Net::SMTP->new($host,
Hello=>'localhost',
Timeout=>120,
Debug=>1
);
# modify it with your email username and password
$smtp->auth('your_email_username','your_email_password');
$smtp->mail($mail_from);
$smtp->to($mail_to);
$smtp->data();
$smtp->datasend("To: $mail_to\n");
$smtp->datasend("From: $mail_from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
$smtp->datasend("$content\n\n");
$smtp->dataend();
$smtp->quit;
}
sub printlog {
my $str = shift;
open LOG,'>>','check_url_status.log' or die "$!\n";
print LOG "$str";
close LOG;
}
url.txt
code: http://www.abc.com http://www.test.com http://www.xyz.com …………………………
…………………………
………………………… http://www.def.com http://www.123.com
本文出自 “BSDerの” 博客,请务必保留此出处http://hellosa.blog.51cto.com/2698675/505781
相关文章推荐
- perl检测网站首页状态
- 利用python并发模块进行网站的状态检测
- shell检测网站状态码和访问时间
- Ping命令检测网站运行状态
- 检测网站状态脚本
- 通过httpstat 检测网站连接速度和状态
- site网站安全状态为危险,提示被篡改检测为被篡改怎么办?
- 网站运行状态检测工具
- 定时检测网站运行状态
- 网站安全/网站状态 检测
- 利用httplib模块监控网站状态
- 中了木马,首页被篡改成 http://www.wz1122.com 了,这是流氓软件,垃圾网站,我终于手动把它删除了
- linux c 检测网络状态
- 2.Reachability检测网络状态
- BootStrap之——网站首页整体设计思路
- 为DataGrid的自带分页添加首页、尾页及状态功能
- IOS检测网络连接状态
- 检测电池电量和充电状态
- 我的第一篇博文,网站首页的菜单展示
- keepllive属性来检测网络连接的状态