I have two scripts in /etc/hotplug.d/iface which I wan to use to perform some actions when the matched interface change state from up to down and vise versa. Below are my scripts.
When interface comes up
#!/bin/sh
if [ "${ACTION}" == "ifup" ] && [ "${DEVICE}" = "eth1" ]
then
echo "local 1.1.1.1" >> /etc/openvpn/tester.ovpn
service openvpn start Wan1
fi
When interface comes down
#!/bin/sh
if [ "${ACTION}" == "ifdown" ] && [ "${DEVICE}" = "eth1" ]
then
sed -i '/local/d' /etc/openvpn/tester.ovpn
service openvpn stop Wan1
fi
As you can see my goal when the interface is coming up is to write the local ip address of the interface which obtains from the DHCP in the .ovpn file and start the respective vpn instance while the opposite action is to remove the line from the file and stop the instance.
However, while testing the scripts, only the echo command seems to be passing as I can see the .ovpn file changes. Sed, start and stop doesn't seems to work.
Any help will be appreciated.
PS. What is the interface variable for the ip address which can be used in echo so I can write the obtained DHCP address?
After adding that line before the if on both scripts I have the following
/sbin/hotplug-call: /etc/hotplug.d/iface/98-Wan1-up: line 6: service: not found
It is not recognizing the "service openvpn start Wan1". However if I run this command in cli manually it works as expected. The same apply for the commands in the scripts for down state.
Regarding the log for the down script it seems that it is not calling it at all.
well combining both in one doesn't work at all. not even the log file is created.
also what I cannot understand is if I don't use the check for the interface in down script how I am going to match it. At a given time more than one interface might became down.
can you please let me know what is the variable for the ip address of an interface so I cannot use it for the obtained DHCP address instead of puting static?