0

I have /sbin/ifup-local set to execute and it works but my virutal interface eth0.2 (vlan2) is the one that gets the IP address I need to run the script . How can i run a bash script when eth0.2 is up ?

I renamed /sbin/ifup-local to /sbin/ifup-eth0.2 and it not work

Using Centos6

0

You can easily achieve this with an initscript (script file under /etc/init.d/), using LSB tag "Required-Start" with "$network" parameter:

### BEGIN INIT INFO
# Provides: After network script launching
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start a network dependent script
# Description: Network dependent script launcher
### END INIT INFO

Use the skeleton here is you haven't your.

Then modify the "do_start()" function to launch your script, for example:

do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started

    cd /my/script/dir && ./myScript.sh

    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one.  As a last resort, sleep for some time.
}

You should modify the "do_stop()" function too to avoid possible shutdown errors.

  • And how would this run when the interface comes up, as opposed to when booting the system after the network service has been started? – RalfFriedl May 19 at 12:57
  • yes i was going to say .......... – youtube-dl fan May 26 at 5:46
  • Script run after network, so its eth0.2 would be up – Leahkim Jun 14 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.