LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-11-2004, 01:19 PM   #1
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,615

Rep: Reputation: 47
I'm looking for a simply perl script to send mail, when ping down


hi

I'm looking for a simply perl script, when ping down,
then sends mail to administrator.

kind regards
cccc
 
Old 01-11-2004, 02:00 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
How about:
Code:
#!/usr/bin/perl

$mail="administrator\@somehost.com";
$host="ip.of.some.host";

$out=`ping -c3 $host | grep -c "bytes from"`;

if($out < 2){
open(MAIL, "|/usr/sbin/sendmail -t");
print MAIL "to:$mail\n";
print MAIL "from:$mail\n";
print MAIL "subject:Cannot ping remote host\n\n";
print MAIL localtime(time());
close(MAIL);
}

exit;
It will attmpt to ping 3 times if less than 2 replies are received then it sends the admin an e-mail.
 
Old 01-12-2004, 04:36 AM   #3
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,615

Original Poster
Rep: Reputation: 47
thanks david_ross

works great !

kind regards
cccc
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
perl send mail code pragti Programming 2 03-17-2006 05:48 PM
Send Mail with Perl Cool_Hand_Luke Programming 2 03-14-2005 09:59 AM
Perl form wont send mail calmbomb Linux - Software 4 11-07-2004 10:08 AM
CGI Script runs to send mail, but mail is never sent robertwo Linux - Newbie 2 06-10-2004 09:57 AM
howto send a mail with attachment via perl script ? cccc Programming 24 03-05-2004 07:49 PM


All times are GMT -5. The time now is 03:07 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration