I have a script (kicks from WiFi low level clients) in infinity loop with sleep 5
#!/bin/ash
thr=-67
bantime=2000
while :
do
sleep 5
maclist=$(iw wlan0 station dump | grep Station | awk '{ print $2 }')
for mac in $maclist
do rssi=$(iw wlan0 station get $mac | grep "signal avg" | awk '{ print $3 }')
if [ $rssi -lt $thr ]
then
ubus call hostapd.wlan0 del_client "{'addr':'$mac', 'reason':5, 'deauth':true, 'ban_time':$bantime}"
logger -p notice -t MY-KICK "DEVICE $mac KICKED WITH SIGANL $rssi dB !!!! "
fi
done
done
I put it to /root/mykika.sh
it works if i put it in rc.local but cant reboot
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
/root/mykika.sh
exit 0
all seams work but i need it to work as a service
so i read Init Scripts
then i made a file in /etc/init.d/mykika with :
I don't know a lot about it but the init.d script isn't the actual program, it registers your program with the procd service. In particular killall S99mykika makes no sense since the init.d script itself only runs once at bootup then exits. procd will take care of startup and stop and respawning if the service crashes.
For a reasonably simple example, install gpsd (a daemon which reads data from a GPS receiver and makes it available on a TCP port) and examine /etc/init.d/gpsd.
And thanks for posting your kick low signal script-- I've made a few attempts to implement the concept as it seems to really help in a festival situation.
and that's it. Note that the script does not even launch the program directly, that is taken care of by procd_open_instance and procd_close_instance. In between the two you can do several things to customize the run, here the only one that I kept is to set the "respawn" flag so if the service crashes, it will restart. And for a service such as this which can be simply killed in order to stop it, the built-in "stop" code is sufficient without adding a custom "stop" routine.
If you set the execute permission on the script it can run directly, there is no need for /sbin/ash /path/to/script, just use /path/to/script as PROG in the file above.
An & sign is unnecessary as each service is launched to the background by procd.
Note that as the wifi interfaces are brought down during preparation to reboot, the iw station dump at the heart of mykika is going to exit with an error due to non-existant interface. It's not clear offhand if that will be gracefully handled.
the manual restart and new PID all makes sense. I'm not sure why it won't kill with killall, though.
I suspect it is having trouble with the while loop, but I'm not sure why that would be the case as it should break out of the loop. But I just ran a simple test and the while is absolutely the issue. Let me think about this a bit more...
Ok... so I have a potential solution, but it is brute force and might cause other issues...
It is running as process "ash"
ps | grep test
18240 root 1308 S ash ./test.sh
18243 root 1308 S grep test
so killall ash will terminate the process.
Maybe you could find the specific process by parsing the output of ps for the ash process that corresponds with your script, then kill that with kill -9 < process ID >