* Callback Function
@ 2021-04-28 3:05 BrainGeek
2021-04-28 6:28 ` Sven Eckelmann
0 siblings, 1 reply; 2+ messages in thread
From: BrainGeek @ 2021-04-28 3:05 UTC (permalink / raw)
To: b.a.t.m.a.n
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Callback Function
2021-04-28 3:05 Callback Function BrainGeek
@ 2021-04-28 6:28 ` Sven Eckelmann
0 siblings, 0 replies; 2+ messages in thread
From: Sven Eckelmann @ 2021-04-28 6:28 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: BrainGeek, Anatoliy Lapitskiy
[-- Attachment #1: Type: text/plain, Size: 1746 bytes --]
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
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-28 6:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 3:05 Callback Function BrainGeek
2021-04-28 6:28 ` Sven Eckelmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).