marchello
Posts: 81
Joined: Fri Oct 11, 2013 8:59 am

run script when wwan0 interface obtains IP address

Tue Dec 16, 2014 6:15 pm

Hi all,

My need is to run script when wwan0 interface obtains IP address.
How do I perform it?
Thanks ahead.

User avatar
DougieLawson
Posts: 39528
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: run script when wwan0 interface obtains IP address

Tue Dec 16, 2014 6:57 pm

Put your script in /etc/network/if-up.d and when network-manager brings the interface up your script will run (it gets $1 set to the interface name when it gets called).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
rpdom
Posts: 17399
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: run script when wwan0 interface obtains IP address

Tue Dec 16, 2014 7:28 pm

Or you could add a line to the interface definition in /etc/network/interfaces.
Here's one of mine

Code: Select all

iface wlan0 inet dhcp
	post-up /usr/local/sbin/netmount
	pre-down /usr/local/sbin/netmount
Don't worry that my interface is set to dhcp on that system.
The "post-up" and "pre-down" means that it runs the script /usr/loca/sbin/netmount after the interface has been brought up and got its IP address and is run again before the interface is closed down.

There are various environment variables passed to the script:
MODE: This contain "start" or "stop" to say what is happening to the interface.
PHASE: This contains the value "post-up" or "pre-down" to tell the script at what stage it is being called.
IFACE: Is the interface name.

There are others, but those are the important ones.

Return to “General discussion”