LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-20-2005, 05:29 AM   #1
mrspcs
LQ Newbie
 
Registered: Sep 2005
Posts: 5

Rep: Reputation: 0
what program to watch the internet connection?


I'm looking for a program/script which reboots my server if it has lost the connection to internet.

is there such a program?

Last edited by mrspcs; 10-20-2005 at 05:49 AM.
 
Old 10-20-2005, 07:00 AM   #2
sailu_mvn
Member
 
Registered: Sep 2004
Location: Hyderabad
Distribution: FEDORA,REDHAT,HOST
Posts: 440
Blog Entries: 1

Rep: Reputation: 30
check kbandwidth.......its really useful
 
Old 10-20-2005, 10:19 AM   #3
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Depending on what the server is used for, chances are it won't be running X in which case kbandwidth is out, even if it does what the OP asked which it doens't look like it does.

mrspcs: Best bet would probably to write a bash script to ping an address you know will be up like google.com or something and give it a timeout value. If it fails, reboot. Something like this, run it in /etc/rc.local
Code:
#!/bin/bash

while 1; do
  ping -c 1 -W 3 google.com
  if [ $? -eq 1 ]; then
    reboot
  fi
done
 
Old 10-20-2005, 10:40 AM   #4
mrspcs
LQ Newbie
 
Registered: Sep 2005
Posts: 5

Original Poster
Rep: Reputation: 0
cs-cam,

Is it also possible to have a script which I can run trough a cron job (then setting it to run it every 5 min or something)?
I'm using webmin / shell to administer the server, so kde apps are out of question

I know how to add cron jobs, but not how to make those scripts, maybe you can help a little
 
Old 10-20-2005, 10:44 AM   #5
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Heh, oops. That script would take up a lot of CPU cycles, forgot to chuck a sleep in there. You could add it to a cron list, or you could put a sleep line in there to only run the loop once every 5 mins.
Code:
#!/bin/bash
# this doesn't loop so it's good to add to a cron job

ping -c 1 -W 3 google.com
if [ $? -eq 1 ]; then
  reboot
fi
Code:
#!/bin/bash
# this will run the check, wait for 300 seconds (5mins) and check again

while 1; do
  ping -c 1 -W 3 google.com
  if [ $? -eq 1 ]; then
    reboot
  fi
  sleep 300
done
---------
Edit: Also, I'll just explain the ping command in case you're unsure what it does. Might be wasting my time or saving yours so you don't need to ask That pings google.com once and gives it 3 seconds to respond. If you don't get a response in 3 seconds it assumes you have no connection and reboots. Change -W 3 to -W 5 or whatever if you want to increase the timeout. Run the ping a few times before running the script to see what the average response time is and then add like 5 seconds to that to allow for when you are connected but there is high load on the network or something

Last edited by cs-cam; 10-20-2005 at 10:48 AM.
 
Old 10-20-2005, 10:51 AM   #6
mrspcs
LQ Newbie
 
Registered: Sep 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for your help cs-cam.
I had to change the -W to -i
Code:
usage: ping [-LRdfnqrv] [-c count] [-i wait] [-l preload]
        [-p pattern] [-s packetsize] [-t ttl] [-I interface address]
But I think it works now
 
  


Reply



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
SUSE Watcher and YOU Cannot Update Mic Q SUSE / openSUSE 7 06-20-2006 09:34 PM
Suse Watcher always Orange Ipsofacto Linux - Software 2 10-03-2005 10:59 AM
Problems with Korn email watcher waterox Linux - Software 0 04-01-2005 01:54 PM
file watcher job bmeckle Programming 1 07-27-2004 03:40 PM
File or direcroty watcher and emailer enkrypter Linux - Software 1 04-15-2004 07:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:10 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration