use Redis;
use Sys::Hostname;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::SMTP;
sub basic() {
$host = hostname;
@lines=qx|/sbin/ifconfig|;
@ip;
print "-" x 80 ."
";
foreach(@lines){
if(/inet addr:([d.]+)/){
push @ip,$1 unless $1 =~ /A127.0.0.1z/;
}
}
print "${yellow}HOST: $host => IP: @ip$normal
";
print "-" x 80 ."
";
};
&basic();
sub send_mail{
if (@_ != 2){print "error
"};
($m,$n) = @_;
my $to_address = $m;
my $CurrTime = time2iso(time());
my $to_address = $m;
my $mail_user = 'zhaoyangjian@zjcap.cn';
my $mail_pwd = 'xxxxx';
my $mail_server = 'smtp.exmail.qq.com';
my $from = "From: $mail_user
";
my $subject = "Subject: zjcap info
";
my $info = "$CurrTime--$n";
my $message = <<CONTENT;
$info
CONTENT
my $smtp = Net::SMTP->new($mail_server);
$smtp->auth($mail_user, $mail_pwd) || die "Auth Error! $!";
$smtp->mail($mail_user);
$smtp->to($to_address);
$smtp->data(); # begin the data
$smtp->datasend($from); # set user
$smtp->datasend($subject); # set subject
$smtp->datasend("
");
$smtp->datasend("$message
"); # set content
$smtp->dataend();
$smtp->quit();
};
$var;
eval{
my $r = Redis->new( server => "127.0.0.1:6379",reconnect => 1,every=>60) or (die "can't connect to redis");
$r = Redis->new( password => 'xxxx' );
$var=$r->get('test');
print "$var is $var
";
$r->quit;
};
print "$var
";
if ( defined($var) ){print "redis could connetct
"}
else
{print "redis is lost",send_mail('zhaoyangjian@zjcap.cn',"@ip-redis is lost
")};