what is the best way to run commands/script, after a specified mac-address is connected to the local network?
In the past I found a solution with adding a file in /etc/hotplug.d/dhcp which looks like this:
#!/bin/sh
if [ "$ACTION" = add ] || [ "$ACTION" = update ]; then
if [ "$MACADDR" = xx:xx:xx:xx:xx:xx ]; then
..commands..
elif [ "$MACADDR" = yy:yy:yy:yy:yy:yy ]; then
..another commands..
fi
fi
One use case it is working without problems, but in my second case I want to execute a script on my OpenWRT, which doesnt't really work.
In this script there is some pre-checking and the base function is to ssh on a client und pushing a rsync-command, and from that point it stops.
But if I execute the script manually it is working without problems.
Maybe there's another way on OpenWRT to execute commands if a specific mac-address is connected? The script needs only to be executed once after coming up.
You might try running the problematic script from a detached shell launched from the hotplug script. That might help if you commands actually expect console output/input.
See
Thanks for your first help, it helps me for 1-2 further steps. But it's still strange.
I changed my dhcp-script like this:
#!/bin/sh
if [ "$ACTION" = add ] || [ "$ACTION" = update ]; then
if [ "$MACADDR" = xx:xx:xx:xx:xx:xx ]; then
sleep 1
etherwake -i br-lan aa:aa:aa:aa:aa:aa
elif [ "$MACADDR" = bb:bb:bb:bb:bb:bb ]; then
if [ -f /tmp/qnap-log ]; then
sleep 1
rm /tmp/qnap-log
fi
if [ -f /tmp/rsync_1 ]; then
sleep 1
rm /tmp/rsync*
fi
sleep 1
(/root/script_qnap/qnap.sh > /tmp/qnap-log) &
sleep 5
fi
fi
First part is working, second executes a sesond script with integrated ssh-rsync commands.
In this second script it looks like this after the pre-checks (as mentioned before)
Additional I created a seperate test-script for testing the routine
#!/bin/sh
if [ -f /tmp/qnap-log ]; then
sleep 1
rm /tmp/qnap-log
fi
if [ -f /tmp/rsync_1 ]; then
sleep 1
rm /tmp/rsync*
fi
sleep 1
(/root/script_qnap/qnap.sh > /tmp/qnap-log) &
sleep 5
After executing the last test-script it starts the main-script and it runs through (also visible in the generated logs).
But if the mains script is executed by the dhcp-script it runs through, but the ssh-rsync commands directly aborts (log is generated, but no content).
Don't really understand as from my point of view the execution of the main script should be the same?!