I’d like to run a bash script that does one thing if a certain device is connected, but a different thing if its not connected (as in connected via Syncthing as you’d see in the web UI).
Is there a simple way to test for e.g. device “Bob” connected or disconnected?
Maybe not quite on topic, but here is a small script I wrote recently to access the info that would show for a disconnected device in the UI, from the command line. If not given a specific device ID, it simply dumps all discovered addresses. It uses jq to parse the output. Might serve as inspiration for the scripting you need.
#!/bin/bash
DEVICE=$1
TMPDISCO=`mktemp`
syncthing cli show discovery > $TMPDISCO
if [ -z "$DEVICE" ]; then
jq . < $TMPDISCO
rm -f $TMPDISCO
exit 0
fi
TMPSTATUS=`mktemp`
syncthing cli show system > $TMPSTATUS
jq .[\"$DEVICE\"].addresses[] < $TMPDISCO | \
while read addr; do
echo -ne $addr"\n\t"
jq .lastDialStatus[$addr].error < $TMPSTATUS
done
rm -f $TMPDISCO $TMPSTATUS