My router will randomly lose connection to everything. I can't ping it, it has no internet, I can't even get to the setup page through a wired connection. It won't fix until I unplug it and plug it back in. This happens a lot. It happened four times in the past 45 minutes/ Maybe it's a broken router, but I got it in November, and I don't have any other issues with it other than being forced to unplug it. So I'm wondering, can I make some kind of script that will check if the router has communication, and if it doesn't then it reboots it? I know dd-wrt has a built in function to do a scheduled reboot, but that doesn't help me. If the router goes out right now, and it's scheduled to reboot every three hours, that doesn't really solve my problem.

I have a Linksys E1200 v1 with DD-WRT v24-sp2 (04/07/12) mini


This should work(or be a step in the right direction) have it run on startup,

while true; do
    ping -c 1 #Note: depending on software version it might be ping -n 1
    con=$? #Get exit code, anything other than 0 is bad
    if [ $con -ne 0 ]; then #If con doesn't equal 0 then
        reboot #This one is pretty obvious
    sleep 60 #Wait a minute between checks
  • Its a good script, but I would put in a much longer sleep period - why tie up all the CPU doing pings, when doing the same thing every 30 or 60 seconds - or even running this script every minute from crontab rather then as a shell on startup could do the same thing. – davidgo Feb 19 '14 at 5:19
  • @davidgo Good point, I hadn't even considered crontab, my script can easily be adapted though if needed. – user270595 Feb 19 '14 at 5:26
  • I tried that script and it put my router into a boot loop. – breebreebran Feb 19 '14 at 5:33
  • @breebreebran If any error occures in the ping command then it will reboot, test ping -c 1 by itself to make sure you don't need -n instead of -c. – user270595 Feb 19 '14 at 6:05
  • I'm curious, what is Shouldn't that be the default gateway instead? Because when the default gateway can't be reached, nothing can communicate. – breebreebran Feb 19 '14 at 22:03

DD-wrt also has a watchdog feature that looks like it would do exactly as you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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