View previous topic :: View next topic |
Author |
Message |
amar_ Tux's lil' helper
Joined: 18 Sep 2006 Posts: 118
|
Posted: Tue Jan 02, 2007 6:43 pm Post subject: How to start connection automaticly? |
|
|
I have this really stupid ISP that kills pppoe conn. every 7 hours.So I need something to start it after it goes down.I have script called bihnet in /usr/bin so I start it with simple 'bihnet' in shell.My question is is there any way to execute that bihnet script every 7 hours and 5 mins for ex.I use rp-pppoe for conecting and somehow every time I start it i have to do 'route add default ppp0' ( so this bihnet script contain that command too).I hope my question was clear (even lil bit long).Thanks for answers.Amar |
|
Back to top |
|
|
harrisonmetz Tux's lil' helper
Joined: 24 Apr 2006 Posts: 93 Location: Chicago, IL
|
Posted: Tue Jan 02, 2007 7:01 pm Post subject: |
|
|
In GNU/Linux there is something called crontab which executes jobs based upon time. You could use that to reestablish a connection every 7 hrs. |
|
Back to top |
|
|
amar_ Tux's lil' helper
Joined: 18 Sep 2006 Posts: 118
|
Posted: Tue Jan 02, 2007 7:08 pm Post subject: |
|
|
I know about crontab.I emerged kcron but I can make command to execute EVERY 7 hours ( I can make it for ex to execute at 7:05,14:10,21:15) but what if I turn on computer at 6?Then command will be executed one hour after.. |
|
Back to top |
|
|
harrisonmetz Tux's lil' helper
Joined: 24 Apr 2006 Posts: 93 Location: Chicago, IL
|
Posted: Tue Jan 02, 2007 7:20 pm Post subject: |
|
|
Do you know any programming. You could create a simple program that you run and it records the first time it connects and just schedules an event to occur 7hrs and 5mins after that. and just repeats the timer. A simple bash script would be:
Code: |
while true; do
echo "Establishing connection"
/usr/bin/bihnet & #Does it run in the backround, if so you dont need &
sleep $(((7*60+5)*60))
done
|
and run that in the backround |
|
Back to top |
|
|
amar_ Tux's lil' helper
Joined: 18 Sep 2006 Posts: 118
|
Posted: Tue Jan 02, 2007 7:26 pm Post subject: |
|
|
Many thanks harrisonmetz. This is what I was looking for (as my scripting is almost 0 ).Will try it.Thanks once again |
|
Back to top |
|
|
Abraxa Apprentice
Joined: 14 Jun 2005 Posts: 174 Location: Germany
|
Posted: Tue Jan 02, 2007 9:57 pm Post subject: |
|
|
Do you use rp-pppoe?
If so you could use a script that polls pppoe-status every 30 seconds and re-establishes the connection if it's down. That way you're not tied to fixed intervals and your connection will stay up.
Then again, if you're using rp-pppoe you can just set "DEMAND=no" in /etc/ppp/pppoe.conf and the link will stay "always-on".
-Soeren |
|
Back to top |
|
|
amar_ Tux's lil' helper
Joined: 18 Sep 2006 Posts: 118
|
Posted: Tue Jan 02, 2007 10:10 pm Post subject: |
|
|
Abraxa can you post that script please(it's allways good to have backup ).But still there is issue with that I have to route add default ppp0 every time pppoe starts.. |
|
Back to top |
|
|
harrisonmetz Tux's lil' helper
Joined: 24 Apr 2006 Posts: 93 Location: Chicago, IL
|
Posted: Tue Jan 02, 2007 10:28 pm Post subject: |
|
|
Who is your provider? what is their motivation for only allowing you to be on 7hrs and 5mins at a time. That would really annoy me! |
|
Back to top |
|
|
amar_ Tux's lil' helper
Joined: 18 Sep 2006 Posts: 118
|
Posted: Tue Jan 02, 2007 10:31 pm Post subject: |
|
|
harrisonmetz wrote: | Who is your provider? what is their motivation for only allowing you to be on 7hrs and 5mins at a time. That would really annoy me! |
Bihnet Bosnian national provider.They just disconect you , and then you can connect 10 sec. later but your IP is changed.Gues why they do that."So you can not run servers " |
|
Back to top |
|
|
Abraxa Apprentice
Joined: 14 Jun 2005 Posts: 174 Location: Germany
|
Posted: Tue Jan 02, 2007 10:53 pm Post subject: |
|
|
I'm guessing by "I have to route add default ppp0 every time pppoe starts" you meant doing a route add default gw ppp0 - if that's not what you meant you can just adjust the route command to your needs:
Code: | #!/bin/bash
interface="ppp0"
interval=60
while(true); do
# Check the state of the pppoe connection
pppoe-status > /dev/null
if [[ "$?" == "1" ]]; then
echo "Link is down, reconnecting..."
pppoe-start
# Wait a little so $interface can go up
sleep 10
# Check if it really is up
if [[ `ifconfig $interface 2>/dev/null | grep $interface` ]]; then
route add default gw $interface
/etc/init.d/ddclient restart
echo "$interface is up again."
else
echo "Failed bringing up $interface, will try again in $interval seconds."
fi
fi
# Wait for a while before checking again
sleep $interval
done |
Enjoy =3
Oh, and I also added a reset of ddclient so your IP can get updated on your dynamic DNS alias since I guess you're using one as well.
-Abraxa |
|
Back to top |
|
|
amar_ Tux's lil' helper
Joined: 18 Sep 2006 Posts: 118
|
Posted: Tue Jan 02, 2007 11:10 pm Post subject: |
|
|
Thanks Abraxa(it's like you know what I have in /usr/bin/bihnet,there is ddclient part too ).And this interval line is in seconds right?
Last edited by amar_ on Tue Jan 02, 2007 11:14 pm; edited 1 time in total |
|
Back to top |
|
|
Abraxa Apprentice
Joined: 14 Jun 2005 Posts: 174 Location: Germany
|
Posted: Tue Jan 02, 2007 11:13 pm Post subject: |
|
|
Yeah, seconds.
-Soeren |
|
Back to top |
|
|
|