OpenWrt Hotplug script trigger problem?

Requirement: Get the current WAN/WAN_6/LAN interface IPv6 address when the PPPoE dial-up is completed or the interface IP address changes, and record it in the log file. Now the function of the script to obtain the interface IPv6 address is normal, but there are some problems with the trigger condition of the OpenWrt Hotplug script.

/etc/hotplug.d/iface

#!/bin/sh

if [$ACTION=ifup -a $INTERFACE=wan ]; then
   sh xxx.sh
fi

The above script will be executed at an indefinite interval of time without executing ifup or without PPPoE.

/etc/hotplug.d/iface

#!/bin/sh

case "$ACTION" in
ifup)
  sh xxx.sh
;;
esac

According to this writing method, then the script triggering feels like normal, I don't know what the problem is.

You are missing a lot of spaces/delimiters, see the proper syntax:
Public IP via VPN - #40 by vgaetera

1 Like

I didn't understand it too much. My doubt is that there are fewer trigger conditions in the script I wrote, and the restriction should be stricter, but this restriction is invalid. The reference method you gave here is more trigger conditions. The trigger condition I want is only to execute the script after pppoe dialing is completed

1 Like

Probably not your issue, but I would use double quotes around the variable names and more importantly spaces around the equality sign so "$ACTION" = "ifup" instead of $ACTION=ifup, like so:

if [ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ]; then
        sh xxx.sh
fi
1 Like

Thank you, I will first test whether the script is normal, this script is an example from other people. What I don't understand is that if the script is not normal, it should not meet the conditions. I read that in the official documentation, hotplug iface has IFUPDATE_ADDRESSES variable

if [ "$IFUPDATE_ADDRESSES" = "1" ] && [ "$INTERFACE" = "wan_6" ]; then
sh xxx.sh
fi

The above script means that the script will be triggered when the IP address of the wan_6 interface changes, and the variable INTERFACE can match the WAN_6 virtual dynamic interface (DHCPv6 client) that is automatically created after PPPoE dialing is completed?

1 Like

Thank you, I will first test whether the script is normal, this script is an example from other people. What I don't understand is that if the script is not normal, it should not meet the conditions.

You can also use hotplug for fw3 that is part of the official release as an example:

if [ "${INTERFACE}" = "wan_6" ] && [ "${IFUPDATE_PREFIXES}" = "1" ];

Now the judgment condition of the script has been changed to the above. After the modification is completed, there is still an abnormal trigger. Observe for a while and then see if there are any problems, thank you!

1 Like

if [ "${INTERFACE}" = "wan_6" ] && [ "${IFUPDATE_PREFIXES}" = "1" ];

The result of the above writing is not correct, and finally changed to the following to achieve the demand

[ "${ACTION}" = "ifup" -a "${INTERFACE}" = "wan_6" ] && {
  ***.sh 
}

I feel that this system is not implemented using standard script syntax. In addition, "${IFUPDATE_PREFIXES}" = "1" only judges this condition. It is clear that the prefix has been modified after PPPoE dialing, but this condition has not been triggered. I don’t know why.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.