Run only specific /etc/network/if-up.d-script for specific interfaces
When the scripts in ifup.d are called a huge selection of environment variables are passed to it, related to the configuration of the particular interface. So for example, if your interface configuration looked like this.
iface eth0 inet manual
dofoo on
Then your script would receive a variable like $IF_DOFOO
with a value of on
.
Knowing that you could put something at the start of your script like
#!/bin/bash
if [ -z "$IF_DOFOO" ] ; then
# this script only applies to interface flagged as dofoo
exit 0
fi
... Doing the foo.
With that in place, that script can easily be placed under if-up.d.
Of course you could also simply look at the $IFACE
value, and hardcode your script to only run for a particular interface or and match it to some other external source of configuration. Look at the other scripts in if-up.d
for some examples of what you can do.
fragwürdig
Linux beginner. I try to learn as much as I can from doing it.
Updated on September 18, 2022Comments
-
fragwürdig over 1 year
I would like to run a network script when bringing up a specific interface (e.g. eth0) by invoking
ifup eth0
The script should ONLY run when bringing up eth0. My approach was to write the script (named
script.sh
) place it somewhere as executable and then write in/etc/network/interfaces
:auto eth0 iface eth0 inet manual up /path/to/script.sh
Is there a more elegant way to do that? Can I use the
/etc/network/if-up.d
scripting environment in some way? As far as I know all scripts in this folder will be run not no matter which interface was brought up.