Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using a script called Responser which sends email when any of the my sites are down/slow. I just wanted to check if it's sending the mail only if the sites are really down or slow(as I checked it accessing as soon I got the error mails and sites was fine). I thought of using wget as it shows the speed and response time and I want to schedule it to compare it with my responser script whether both sends the mail at the same time saying error.

I've postfix installed and I could send mails using mail command to any e-mail id from the terminal. I want the output of wget http://www.mysite.com to be mailed with the condition if response time is greater than 5 seconds. Then I can schedule it to run at every 5 mins. I saw many having good programming skills here and hope someone could help me.

Thanks!

share|improve this question

1 Answer 1

The script you want is something like this:

#!/bin/bash
# by desgua to test server down
# 
# This script is supposed to be named ".ping.time.sh" and
# to be put at ~/
# to test what happens when server is down: 
# change www.mysite.com for www.serverdown.com  
# 
# As asked, I supposed you have a script to send mail and named
# ~/.script.to.send.mail.sh 
# 
sleep 300          # as asked, to run at every 5 minutes
pingtime=$(ping -w 5 www.mysite.com | grep ttl)

echo $pingtime

if [ $pingtime = ] ; then 
   echo 'down' ; ~/.script.to.send.mail.sh ; else
   echo 'up' ; ~/.ping.time.sh
fi

ps. At your script to send the email, put something to run again the script I made after the mail has been sent

share|improve this answer
    
The domain names are globally registered but I couldn't ping to them –  user3215 Apr 22 '11 at 2:12
    
PING www.mysite.com (204.200.xx.xx) 56(84) bytes of data. ^C ---www.mysite.com ping statistics --- –  user3215 Apr 22 '11 at 3:24
    
No, it's just an output of ping www.mysite.com –  user3215 Apr 22 '11 at 4:16
    
I have firewall settings on my server and so it won't ping –  user3215 Apr 24 '11 at 4:16
    
You sure know how to configure it to allow ping, right? You don't want to allow ping or you need help to configure it? –  desgua Apr 24 '11 at 11:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.