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 $ @;
}
}