Startup script to swap between PPPOE connections (for Afterhours uncapped)

DrJohnZoidberg

Honorary Master
Joined
Jul 24, 2006
Messages
23,995
I recently moved over to an afterhours account because I'm not really ever at home before 7pm. The only problem is that the after hours uncapped account is throttled to 192kbps during the day which is pretty useless if I want to ssh or ftp remotely or if I am at home that day and want to browse around.

The solution: use my free afrihost gig for during the day and then switch over at 7pm to the after hours account - this would be a mission to do in the router the whole time (if only my router could do this) so I decided to write a simple bash script to do it for me. I also have a cronjob running which will switch accounts automatically while I'm logged on.

The script connects with the normal capped account if its between 7am and 7pm on a weekday and connects to the after hours account if its after 7pm and on weekends.

Anyway here is the startup script, maybe somebody else finds it useful (or can improve on it):

Code:
#!/bin/bash

nowtime=$(date +%H%M)
nowday=$(date +%w)

starttime=700
endtime=1900

normalaccountname='dsl-provider'
afterhoursaccountname='afterhours'

if ifconfig | grep ppp > /dev/null
	then

	echo "PPPOE connection already active!"
	exit
	else

	if [ "$nowday" -ge "1" ] && [ "$nowday" -lt "6" ]
		then
		if [ "$nowtime" -ge  "$starttime" ] && [ "$nowtime" -le "$endtime" ]
			then
			pon $normalaccountname
			echo "Weekday between $starttime and $endtime"
		else
			pon $afterhoursaccountname
			echo "Weekday between $endtime and $starttime"
		fi
		else
		pon $afterhoursaccountname
		echo Weekend Baby!
	fi
fi

I haven't actually tested it very much so it may not even work properly. Hehe, I will update as I use it during the week.

Remember this is only a start up script, I am also using a cronjob to switch over while the pc is on (that script is still very messy, so don't want to post it here yet).

Hope somebody finds this useful!

EDIT: Oh yes, this must be run as root, so you would place it in a root crontab with the @reboot flag.
 
Last edited:

MrWireless

Well-Known Member
Joined
Jun 24, 2006
Messages
327
I am actually looking for something like this, but not sure how to do it.

I am using Routertech firmware on a Mega1000wr, anyone have any idea?
 

MyWorld

Executive Member
Joined
Mar 24, 2004
Messages
5,001
What exactly are you looking at doing and what version of Linux do you run?
 

MrWireless

Well-Known Member
Joined
Jun 24, 2006
Messages
327
What exactly are you looking at doing and what version of Linux do you run?

Erm, ok. During the day I want it to connect to my Mweb account (7am-7pm). Then during the evenings I want it to connect to my openweb 10MB account (7pm-7am)

Version of linux, erm....
Operating system version
Linux version 2.4.17_mvl21-malta-mips_fp_le (developers@RouterTech.Org) #1 Tue Jan 5 15:37:05 GMT 2010
 

MyWorld

Executive Member
Joined
Mar 24, 2004
Messages
5,001
The script listed here is not a router script, but a PPPoE script you run from your PC.

You can take the script just as is, create two PPPoE configs (in the script they are named "dsl-provider" and "afterhours") and add the script to you crontab.

You should PM the OP to get the rest since this is only part of the config. Ask him to share his crontab entries and if there were any changes to this script.
 

DrJohnZoidberg

Honorary Master
Joined
Jul 24, 2006
Messages
23,995
Erm, ok. During the day I want it to connect to my Mweb account (7am-7pm). Then during the evenings I want it to connect to my openweb 10MB account (7pm-7am)

Version of linux, erm....
Operating system version
Linux version 2.4.17_mvl21-malta-mips_fp_le (developers@RouterTech.Org) #1 Tue Jan 5 15:37:05 GMT 2010

From what I can figure out, the version info you posted above is your router running a stripped down linux kernel. This is not what this script was intended for, however I suppose it would work in theory, however I wouldn't screw around with your router. If however you are also running a Linux distribution on your computer, let me know what distribution it is and I will be able to give you a more detailed how-to.
 

MrWireless

Well-Known Member
Joined
Jun 24, 2006
Messages
327
From what I can figure out, the version info you posted above is your router running a stripped down linux kernel. This is not what this script was intended for, however I suppose it would work in theory, however I wouldn't screw around with your router. If however you are also running a Linux distribution on your computer, let me know what distribution it is and I will be able to give you a more detailed how-to.

Cool, a while ago I did setup connection splitting directly on the router to split local from international - from a guide here in MBB. I changed the default firmware to routertech to be able to do it...it was just such a long time ago that I dont remember it at all. But I do recall the router supporting cron jobs and creating connections via the script....so I think I need to hunt that down, and see if I cant modify it do create connections at certain times instead of splitting a connection. Should be easy enough.

Will work on it tomorrow and let you guys know how it went ;)
 

nahoR

Well-Known Member
Joined
Mar 29, 2010
Messages
344
Get a Mikrotik RB750. Put your Mega*something* in bridge mode and config the RB750 to make the PPPoE connections. Much easier and great support on the Mikrotik wiki
 
Top