This little guide will show you how I've set up my Raspi to reset my router every day (it's a long story but one of my routers is very unstable in its current set up and I haven't figured out how to fix it yet).
UPDATE:
I forgot to mention which router I use this script for. It's a ASUS RT N66U.
As Jeroen pointed out in the comments it can be a bit more complicated if you use other routers. If you have a Fritz!box (xs4all tends to supply these as modems/routers) you are in luck:
https://github.com/jpluimers/bash-fritzclient
REQUIREMENTS
- A raspberry pi
- A router with telnet access
- Some basic knowledge of linux, bash and cron jobs
LET'S GO!
First you probably need to install telnet:
#install telnet
sudo apt-get install telnet
Now you have telnet give it a try and log in with your router
#create a connection
telnet [ip-of-router]
You should be prompted for your username and password. Once you provided these, try the reboot command:
#reboot router
reboot
If this is all working we can move on to the next step: create a little bash script that runs a bunch of commands. It doesn't really matter where you put it but I like to have it in /home/pi/scripts/
#create directory
mkdir ~/scripts
#create file
nano ~/scripts/cronjob-router-reboot.sh
Paste the following script
#!/bin/sh
# replace cmd1 for the command to execute
host=192.168.0.179
port=23
user=YOURUSERNAME
pass=YOURPASSWORD
cmd1='reboot'
rm -f /home/pi/scripts/log-cronjob-router-reboot.txt
( echo open ${host}
sleep 2
echo ${user}
sleep 1
echo ${pass}
sleep 1
echo ${cmd1}
sleep 1
echo quit
sleep 2
) | /usr/bin/telnet > home/pi/scripts/log-cronjob-router-reboot.txt
You do need to edit the 'host', 'user' and 'pass' values at the top :). Press Ctrl+X, Y and then ENTER to save the file and exit.
Now make the file executable:
#make executable
chmod +x cronjob-router-reboot.sh
And try it out!
# run script
/home/pi/scripts/cronjob-router-reboot.sh
The last thing we need to do now is add it as a cron job. Cron, in case you don't know, is like Windows' Task Scheduler: it lets you run things at a given time and/or interval.
#open crontab
crontab -e
At the bottom, paste the following to start the job every day at 4:00 in the morning (see the text for a short description of that the first 5 characters do and how you can use them to schedule things)
0 4 * * * /home/pi/scripts/cronjob-router-reboot.sh
That's it! Save it and exit. Your raspberry should now reboot your router every day at 4:00 AM :D