我的第一个用于生产环境的perl脚本,虽然不是很优秀,但也迈出了扎实的一步 :)
领导有任务,给一批IP列表,ping每一台机器,如果没有响应就发邮件通知,通知的邮件需要分开,不能通知一个列表,得一封一封的通知.
用到email::send模块,因为需要用到Gmail

复制代码代码如下:
#!/usr/bin/perl 
use warnings; 
use strict; 
use Email::Send; 
use Email::Send::Gmail; 
use Email::Simple::Creator; 
my @list = qw/ 
1.1.1.1 
2.2.2.2 
3.3.3.3 
/; 
foreach my $re (@list){ 
        my $p = `ping $re -c 3`; 
        if($p=~/100% packet loss/){ 
                my $email = Email::Simple->create( 
                header => [ 
                From    => 'monitor@a.com', 
                To      => 'monitor@b.com', 
                Subject => "$re 100% packet loss", 
], 
body => "$re the server is down!\n", 
 ); 
                my $sender = Email::Send->new( 
                { mailer => 'Gmail', 
                mailer_args => [ 
                username => 'monitor@a.com', 
                password => 'xxx', 
                ] 
                } 
); 
        eval { $sender->send($email) }; 
        die "Error sending email: $@" if $@; 
        } 
}

原文链接:http://www.jb51.net/article/33965.htm

最新文章

  1. ubuntu 16.04 Dockerfile 安装mysql
  2. python高级之面向对象高级
  3. <<< Tomcat 部署项目There are no resources that can be added or removed from the server
  4. two day python基础知识
  5. java 的数据类型
  6. linux之unlink函数解析
  7. 解决VS2013中“This function or variable may be unsafe”的问题
  8. Win7删除右键菜单中“图形属性”和“图形选项”
  9. 带着新人学springboot的应用05(springboot+RabbitMQ 上)
  10. Failed to create the XA control connection. Error: "找不到存储过程 'master..xp_sqljdbc_xa_init_ex'。
  11. Python全栈学习_day007作业
  12. DFS基础题
  13. C++中 线程函数为静态函数 及 类成员函数作为回调函数
  14. django面试三
  15. VC 字符串转化和分割
  16. luasocket 接收数据
  17. SQLAlchemy并发写入引发的思考
  18. 【Docker】第四篇 Docker仓库管理
  19. [POI2012]STU-Well
  20. 牛客练习赛9 B - 珂朵莉的值域连续段

热门文章

  1. [置顶] 《MFC游戏开发》笔记一 系列简介
  2. MPMoviePlayerController过期导致视频播放时间条颠倒及AVPlayerViewController的用法
  3. CentOS-6.5安装配置Tomcat7
  4. zabbix电话告警V1
  5. [转]在SQL中用正则表达式替换html标签
  6. LeetCode 260
  7. [BigData]关于HDFS的伪分布式安装和虚拟机网络的配置
  8. MultiMap、BidiMap及LazyMap的使用
  9. RedirectFromLoginPage和FormsAuthenticationTicket的区别
  10. Android:Xml(读取与存储)