LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2012, 05:46 AM   #1
KatrinAlec
Member
 
Registered: Feb 2012
Posts: 116

Rep: Reputation: 13
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?
 
Old 08-22-2012, 03:05 PM   #2
mpapet
Member
 
Registered: Nov 2003
Location: Los Angeles
Distribution: debian
Posts: 548

Rep: Reputation: 72
#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
 
Old 08-23-2012, 01:37 AM   #3
KatrinAlec
Member
 
Registered: Feb 2012
Posts: 116

Original Poster
Rep: Reputation: 13
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.
 
Old 08-23-2012, 03:15 PM   #4
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
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.
 
Old 08-24-2012, 01:03 AM   #5
mpapet
Member
 
Registered: Nov 2003
Location: Los Angeles
Distribution: debian
Posts: 548

Rep: Reputation: 72
Quote:
Originally Posted by KatrinAlec View Post
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?
 
Old 08-24-2012, 01:27 AM   #6
KatrinAlec
Member
 
Registered: Feb 2012
Posts: 116

Original Poster
Rep: Reputation: 13
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.
 
Old 08-24-2012, 07:01 AM   #7
ambrop7
Member
 
Registered: May 2011
Distribution: Gentoo
Posts: 98

Rep: Reputation: 16
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.

Last edited by ambrop7; 08-24-2012 at 07:54 AM.
 
Old 08-24-2012, 07:52 AM   #8
KatrinAlec
Member
 
Registered: Feb 2012
Posts: 116

Original Poster
Rep: Reputation: 13
I'll have a look into that.
Thanks.
 
  


Reply

Tags
ifup, ppp, script



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sharing ppp connection with wlan interface viniciusandre Linux - Networking 1 10-01-2009 10:35 AM
PPP client taking the IP address of the eth interface... culin Linux - Networking 0 06-22-2007 01:18 AM
ppp interface... culin Linux - Networking 4 04-13-2007 03:49 PM
Timeout expired while waiting for the PPP interface kebbelj Linux - Networking 0 02-13-2005 03:24 PM
waiting for the PPP interface ertz Linux - Networking 2 05-17-2004 04:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration