... but still, I don't like how
lease-script works here :(. When user leaves the house, it does not trigger anything, but then user comes back
lease-script is triggered twice -
offline and
online.
I wrote simple shell script, so my raspberry could
ssh to Mikrotik, get recent
registration-table and after simple comparison with
diff send those hooks on behalf of Mikrotik:
#!/bin/sh
new=/tmp/registration-table.new # define a file for new registration-table ...
old=/tmp/registration-table.old # ... and for previous one
[ -f $new ] && mv $new $old || touch $old # shift "new" table to "old", as we will get newer soon.
# If this is a first run - create empty "old" table ...
# ... so diff command would not complain
# ssh to Mikrotik (with ssh keys) and print fresh registration-table
# awk - let the field separator be " " and "=" characters. ...
# ... Leave only 6-th column (mac address) and store whole output as "new" table
ssh admin@192.168.88.1 /interface wireless registration-table print terse |awk -F'[ =]' '{print $6}' > $new
# diff - let's use more meaningful online/offline labels instead of > < to display differences between tables
# grep - filter diff command output and leave lines only with our defined labels
# while - with each line store 1st column to ${status} variable (online/offline) and 2-nd to ${mac}
diff --old-line-format="offline %L" --new-line-format="online %L" $old $new | egrep "line"|while read status mac
do
# finally silently call our webhook with recent updates in the "new" table
curl -so /dev/null "http://myddnshost123at.duckdns.org:1880/wifi?status=${status}&mac=${mac}"
done
But i don't like
ssh in this script now :D Its too heavy/slow/unnecessary and for security reasons too...
I am complete newbie in RouterOS and I would really appreciate if someone would rewrite similar logic to its native script language.
Few more questions:
* Does RouterOS have cron daemon or something similar? Can it schedule job to run each 15s?
* Would it be significant load increment for Mikrotik to run such script each 15s or 1min if there is no such fine granularity?
Thanks in advance!
PetrasL