With ALFRED I've noticed a parameter you can pass into it labeled "-c" which is described to be a callback. I've tried things like "-c poweroff" just to make it obvious that the callback worked, but to no avail. How can I properly use this feature and how does it work?
I'm currently running ALFRED and batman-adv on my Raspberry Pi 4. All the software is up-to-date.
On Wednesday, 28 April 2021 05:05:47 CEST BrainGeek wrote:
With ALFRED I've noticed a parameter you can pass into it labeled "-c" which is described to be a callback. I've tried things like "-c poweroff" just to make it obvious that the callback worked, but to no avail. How can I properly use this feature and how does it work?
Please have a look at the manpage [1].
Specify command to execute on data change. It will be called with data-type list as arguments.
As you can see, the called command will have additional values added to the end. So you have to keep in mind that some commands don't like it when they receive extra parameters at the end. Let us simulate this with poweroff:
$ poweroff 1 Too many arguments.
So this will not work. You have to add some kind of wrapper which evaluates the numbers and then calls poweroff at the appropriate time. Let us define a small test script on host 1.
host1$ cat > /tmp/alfred_cmd.sh << "EOF" #! /bin/sh
echo "$(date): $@" >> /tmp/alfred_cmd_log
for i in "$@"; do if [ "$i" = "123" ]; then poweroff fi done EOF
host1$ chmod +x /tmp/alfred_cmd.sh
And now start the alfred instances on both hosts:
host1$ alfred -m -i bat0 -c /tmp/alfred_cmd.sh host2$ alfred -m -i bat0
You can now inject data on host2
host2$ echo foobar | alfred -s 65
and see the changed data-types on host1
host1$ touch /tmp/alfred_cmd_log host1$ tail -f /tmp/alfred_cmd_log
If you write something to data-type 123 and you alfred instance is running with high enough privileges then it might shut down the system.
Kind regards, Sven
[1] https://downloads.open-mesh.org/batman/manpages/alfred.8.html
b.a.t.m.a.n@lists.open-mesh.org