Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to execute a shell script from udev rule, when a network interface is added, as follows:

SUBSYSTEM=="net", ACTION=="add", KERNEL=="eth*", PROGRAM="/usr/local/bin/changemac.sh", NAME="eth0"

The shell script is just changing the MAC address of eth1 using ifconfig command, as follows:

#!/bin/sh
/sbin/ifconfig eth0 hw ether 00:cc:dd:ee:ff:e1
echo "command return status $?" > /root/changemac.log

Above script is working fine from command prompt, but not executing from udev rule. I also try to use RUN instead of PROGRAM in udev rule but no success:

SUBSYSTEM=="net", ACTION=="add", KERNEL=="eth*", RUN="/usr/local/bin/changemac.sh", NAME="eth0"

Same script is executing from my custom module udev rule.

I think somebody must know this why it is not executing from network udev rule. :-)

share|improve this question
    
PROGRAM is definitely wrong: this is executed before the device is activated, to determine how and whether it should be activated. I don't see anything wrong with the RUN rule. Does anything appear in the system logs? Did you run udevadm trigger to reapply the rule? What does udevadm test net/eth0 show? –  Gilles Jan 24 '13 at 22:41
    
if it executed before the device is activated, then just add sleep time in your script then it will run later, have you tried this ? –  Rahul Patil Mar 16 '13 at 3:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.