OpenWrt Forum Archive

Topic: pppoe disconnect via crond

The content of this topic has been archived on 5 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I would like to disconnect/connect to my ISP via crond at certain times.  My ISP is disconnecting me anyway every 24 hours, so I want do it at night to be not interrupted at daytime.

Maybe this is a newbie question, but I searched this forum, the faqs etc. without luck.

Thanks for your help and a happy new year to all of you!

         Andreas

I use following set-up:

create /etc/init.d/S49crond    with contents:
##########################################
#!/bin/sh
# start crond, working from the //etc non-volatile directory tree
mkdir -p /var/spool/cron/crontabs
cp /etc/cron.root /var/spool/cron/crontabs/root
/usr/sbin/crond
##########################################

create /etc/init.d/freshstart    with contents:
##########################################
#!/bin/sh
IFS=

# kill pppoe and adsl link
/usr/bin/killall -9 ifup.pppoe
/usr/bin/killall -9 pppd

# here I have code that talks to the adsl modem via nc and resets the modem

# reset the wrt54g (or you could just do a ifdown wan ; ifup wan, make sure any route info gets defined again)
/sbin/reboot
##########################################

create /etc/cron.root with example contents (used by crond start script)
##########################################
# at 05:50 every day
50 05 * * * /etc/init.d/freshstart
##########################################

I enabled cron as described in the HowtoEnableCron Wiki page and add a cronjob like this:

root@OpenWrt:~# crontab -l
0 4 * * * /sbin/ifup wan
root@OpenWrt:~#

That's it.

EDIT: there is no need to use "/sbin/ifdown wan ; sleep 10". ifup disconnects it automatically if there is already a connection up.

(Last edited by olli on 10 Jan 2006, 14:25)

should'nt be killing pppd enough for a simple hangup + redial?
It is also very fast, only a few seconds till reconnect.

Hi olli,

olli wrote:

I enabled cron as described in the HowtoEnableCron Wiki page and add a cronjob like this:

root@OpenWrt:~# crontab -l
0 4 * * * /sbin/ifdown wan ; sleep 10 && /sbin/ifup wan
root@OpenWrt:~#

That's it.

I'm using your code now: works nicely.

Thanks

Andreas

I do a check_online (every 15 minutes in cron) :

O=`ping -c 1 a_server_known_to_be_pingable | grep "1 packets received"|wc -l | sed -e "s/ //g"`
if [ $O -eq 0 ]; then
        killall pppd
fi

Gregoire: This is not, what the original poster wanted. He wanted to have a planned disconnect/reconnect at 04:00 o'clock.

This is how I do it:

root@OpenWrt:/etc# crontab -l
# issue a reconnect at 05:00 CET
0 5 * * * kill `pidof pppd`

my firmware is HyperWRT 2.1b1 +tofu13c

when i connect via SSH i got

# ps -elf | grep cron
19992 root        312 S   cron
20636 root        308 S   grep cron

http://wiki.openwrt.org/HowtoEnableCron tells to "Create the file /etc/init.d/S61crond containing:"

but i got no /etc/init.d/ directory

Create the file /etc/init.d/S61crond containing:

# cd etc
# ls -l
lrwxrwxrwx    1 0        0              11 Feb  3  2006 TZ -> /tmp/etc/TZ
lrwxrwxrwx    1 0        0              11 Feb  3  2006 cron.d -> /tmp/cron.d
lrwxrwxrwx    1 0        0              14 Feb  3  2006 group -> /tmp/etc/group
lrwxrwxrwx    1 0        0              10 Feb  3  2006 hosts -> /tmp/hosts
-rw-r--r--    1 0        0             711 Feb  3  2006 ld.so.cache
-rw-r--r--    1 0        0              14 Feb  3  2006 ld.so.conf
-rwxr-xr-x    1 0        0            7651 Feb  3  2006 openssl.cnf
lrwxrwxrwx    1 0        0              15 Feb  3  2006 passwd -> /tmp/etc/passwd
-r--r--r--    1 0        0              74 Feb  3  2006 profile
-r--r--r--    1 0        0            5834 Feb  3  2006 protocols
lrwxrwxrwx    1 0        0              16 Feb  3  2006 resolv.conf -> /tmp/resolv.conf
-r--r--r--    1 0        0           11955 Feb  3  2006 services

___________________________________________________________________________

i find a crontab under

# cd ..
# cd tmp
# ls
-rw-r--r--    1 0        0               8 Jul 18 15:57 action
drwx------    1 0        0               0 Jan  1  1970 cron.d
-rw-------    1 0        0              36 Jul 18 15:57 crontab
drwxr-xr-x    1 0        0               0 Jan  1  2000 etc
-rw-------    1 0        0               0 Jul 18 15:34 hosts
lrwxrwxrwx    1 0        0               8 Jan  1  1970 ldhclnt -> /sbin/rc
-rw-r--r--    1 0        0              40 Jan  1  1970 nas.lan.conf
drwxr-xr-x    1 0        0               0 Jan  1  1970 ppp
-rw-------    1 0        0              21 Jul 18 15:34 resolv.conf
-rw-r--r--    1 0        0              27 Jan  1  1970 ses.log
-rw-r--r--    1 0        0               0 Jan  1  1970 startup.log
-rwx------    1 0        0             218 Jan  1  1970 startup.sh
drwxr-xr-x    1 0        0               0 Jan  1  2000 var

___________________________________________________________________________

# crontab -l
-sh: crontab: Permission denied

The discussion might have continued from here.