Script code of the perl ping Detection Function

Source: Internet
Author: User
Tags perl script

My first perl script for the production environment, although not very good, has also taken 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.

Copy codeThe Code is as follows :#! /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 $ @;
}
}
Related Article

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.