LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   script if ppp interface is up (http://www.linuxquestions.org/questions/linux-networking-3/script-if-ppp-interface-is-up-4175423390/)

KatrinAlec 08-22-2012 06:46 AM

script if ppp interface is up
 
I'd like to write a script which will send an email if the ppp interface goes up.

I've found that it might have something to do with the path
/etc/sysconfig/networkdevices/ifconfig...
but I can't quite work it out.

I guess I'll have to write the script and copy it somewhere into the correct path and it will be run if for example ppp12 goes up.

Is that true, and if so, which path would it be?

mpapet 08-22-2012 04:05 PM

#1. Pick a scripting language that works for you.
#2. I use 'ip'. You could use that to get status like this my $var = `ip link show eth0` | grep -c UP

KatrinAlec 08-23-2012 02:37 AM

Thanks for the answer.
I'm using that in a different script, but that would mean I'd have to run a cronjob to test it rather often.

I'm looking for a way to start a script automatically as soon as the link goes up without a script having to test if the link is up.

kakaka 08-23-2012 04:15 PM

It may not seem like the most efficient approach in the World, but depending on the hardware you have, and how you use the hardware, if you're not familiar with it, you might discover that you already have things running in the "background", which check hotplug/removable devices and such, every few seconds, for status changes.

If you were willing to check the ppp link status periodically, you wouldn't necessarily have to accept all the overhead of frequently running a cron job. instead, you could just write a script which starts at the proper time during the boot sequence, sits in the background, in a loop with a delay, periodically checking ppp link status.

However, the larger issue is, under what circumstances is the ppp link being brought up, when you wish to receive notification email?

For example, in certain circumstances, with some distros., some ppp control can involve calling an ifup script, which has a provision for calling an optional script after the interface is up, by setting the POST_UP_SCRIPT config. value.

Alternatively, if in your situation, bringing up the link is handled purely by a ppp daemon, but the daemon has a fairly full compliment of switch hooks, init, connect, welcome, disconnect, etc., then you may be able to simply provide the appropriate script, or tie into a script if it already exists.

Running either:

Code:

man ifup
or:

Code:

man pppd
on your system, may provide you some information specific to your system. If those don't get you any info. you can try:

Code:

apropos ppp
or if you find that you don't have the apropos command, this should work:

Code:

man -k ppp
HTH.

mpapet 08-24-2012 02:03 AM

Quote:

Originally Posted by KatrinAlec (Post 4761786)
Thanks for the answer.
I'm using that in a different script, but that would mean I'd have to run a cronjob to test it rather often.

I'm looking for a way to start a script automatically as soon as the link goes up without a script having to test if the link is up.

Well, that is the business of /etc/network/interfaces if you aren't using networkmanager or wicd. What would be the harm of running a split-second job every few minutes?

KatrinAlec 08-24-2012 02:27 AM

I've found an ip-up script in /etc/ppp/ which seems to be run each time an interface goes up.
So if I add my own script it should work.

The problem with the cron job is mainly that we're using the ppp interfaces for backup.
There are about 60 of those and only for some I need a notification.

And those "important ones" should technically only go up in case of failure, so basically never.

I do have a cron job which checks every hour if an interface is up, and it's not such a complicated one because I've made sure that the interfaces which are allowed to be up aren't up at the time the cron job is run.

But now I've found that there was an interface I would have liked to know about, was up serveral times an hour, but hardly ever when the cron job was run, because the call was only very short. So I'd have to run the cron job every minute and then I'd have to check the results against a list with "allowed" ppps.

That's still possible, but even those "allowed ppps" aren't allowed to be up for very long, so I'd have to adapt the script again, checking the call duration, making it very complicated...

I know, I'm being difficult....;)

But I think ip-up might work.

ambrop7 08-24-2012 08:01 AM

My NCD scripting language can do this and much more. The following script will run some command when the link goes up and another command when it goes down.

Code:

process interface_watcher {
    # Choose device.
    var("eth0") dev;

    # Wait for device to start existing.
    net.backend.waitdevice(dev);

    # Wait for link to go up.
    net.backend.waitlink(dev);

    run({"/command/to/run/when/goes/up", "arg1", "arg2"},
        {"/command/to/run/when/goes/down", "arg1", "arg2"});
}

Note that this observes the link status (IFF_RUNNING interface flag). For wired devices e.g. this means the cable is plugged in and working. It doesn't mean that an IP address has already been assigned. Ideally you would use NCD to configure everything not just observe link status, to avoid such races.

KatrinAlec 08-24-2012 08:52 AM

I'll have a look into that.
Thanks.


All times are GMT -5. The time now is 06:42 PM.