detect if other device connected via terminal?

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?


  • Dave

You can use the REST-API (GET /rest/system/connections — Syncthing documentation) or the cli for this specific use case.


syncthing cli show connections

And filter out the device you want to decide your logic on, more specifically

  "device-id...-...-...-...-...-...": {
      "address": "...:22000",
      "at": "2023-11-27T19:28:52+01:00",
      "clientVersion": "v1.26.1",
      "connected": true,

Or use the linked Rest-API call which gives practically the same output.


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.



syncthing cli show discovery > $TMPDISCO

if [ -z "$DEVICE" ]; then
    jq . < $TMPDISCO
    rm -f $TMPDISCO
    exit 0

syncthing cli show system > $TMPSTATUS

jq .[\"$DEVICE\"].addresses[] < $TMPDISCO | \
    while read addr; do
        echo -ne $addr"\n\t"
        jq .lastDialStatus[$addr].error < $TMPSTATUS


Thanks to both of you :slight_smile: That gives me a lot to work with!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.