PDA

Bekijk de volledige versie : How to run a script when pppd connects/disconnects



Khurram
21-04-2010, 22:29
I would like to run a script when pppd connects/disconnects. In Ubuntu, it is simple: I just add the script to /etc/ppp/ip-up.d and /etc/ppp/ip-down.d folders. In the koppel's mod of Oleg firmware, I just add the ip-up and ip-down scripts in /tmp/ppp folder.

But this does not work in 1.9.2.7-d-r1222. The ip-up and ip-down are symlinked to /sbin/rc. If I replace this ip-up with my ip-up, I get problems. It seems the builtin ip-up populates resolv.conf with the dns servers of my connection. I can get around this by hardcoding the dns servers. But I would rather not do it in this kludgy manner. Besides, I dont know what else does the /sbin/rc program do.

I have tried the Ubuntu way with ip-up.d folder, but it is ignored. I searched through the posts and found one which suggested adding the ip-up to /tmp/etc/ppp folder; but this does not work as the script is ignored.

Is there anyway to execute scripts on pppd connection/disconnection?

Thanks.

Khurram
23-04-2010, 16:00
Okay, I have been playing around with this. It seems that the ip-up and ip-down are symlinked to a binary which does all the work. I decided to replace these links to my up/down scripts. Basically, I duplicated how Ubuntu does it (Ubuntu uses ip-up.d and ip-down.d directories to contain the scripts to run and a master ip-up and ip-down scripts as the entry point from pppd).

I used the ip-up and ip-down scripts from Ubuntu and edited them as I did not need as some of things. For ip-up.d folder, at least make a script to set /tmp/resolv.conf and sync datetime. I added these new files/directories to flash, rebooted and voila, it worked :D

If someone is interested, I can post more details here.

Khurram
21-05-2010, 20:26
Ok, the above method required a lot of tweaking to cover for the functions carried out by the "rc" utility. I got tired of trying to mimic its functionality. So I decided to modify the sources to call another script when ppp connects/disconnects. I called these scripts ip-up.local and ip-down.local. These get called after rc has done all the work, the usual parameters for ip-up/ip-down get passed to the scripts and I can add my commands to these .local files. Works great :D

I think it is a really useful feature and would like to submit a patch to whoever is maintaining the firmware (its not much of a patch actually, just 2 lines). Can someone guide me in the right direction here?

Thanks.