Write ping scripts in perl

Source: Internet
Author: User
Tags perl script

My first perl script for the production environment, although not very good, but also took a solid step :)
The leader has a task to send a batch of IP addresses to the list and ping each machine. If no response is received, an email notification is sent. The notification emails must be separated and cannot be sent to a list. A notification must be enclosed.
Use the email: send module because Gmail is required.

#! /Usr/bin/perl
Use warnings;
Use strict;
Use Email: Send;
Use Email: Send: Gmail;
Use Email: Simple: Creator;
My @ list = qw/
192.168.1.2

192.168.2.3

192.168.5.3
/;
Foreach my $ re (@ list ){
My $ p = 'Ping $ re-c 3'; three icmp requests
If ($ p = ~ /100% packet loss /){
My $ email = Email: Simple-> create (
Header => [
From => 'Monitor @ hongshu.com ',
To => 'Monitor @ hs.com ',
Subject => "$ re 100% packet loss ",
],
Body => "$ re the server is down! \ N ",
);
My $ sender = Email: Send-> new (
{Mailer => 'gmail ',
Mailer_args => [
Username => 'Monitor @ hongshu.com ',
Password => 'xxx ',
]
}
);
Eval {$ sender-> send ($ email )};
Die "Error sending email: $ @" if $ @;
}
}
 

This article is from the blog "let me men grow together" and will not be reproduced!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.