# Help scripting with rest/system/connections

**URL:** https://forum.syncthing.net/t/help-scripting-with-rest-system-connections/15103
**Category:** Development
**Created:** [June 1, 2020, 7:48am UTC](https://forum.syncthing.net/t/help-scripting-with-rest-system-connections/15103 "2020-06-01T07:48:29Z")
**Posts on this page:** 1
**Showing post:** 18

<div class="post-metadata">

### Author: ![cosas](https://forum.syncthing.net/user_avatar/forum.syncthing.net/cosas/32/14159_2.png) [@cosas](https://forum.syncthing.net/u/cosas)
#### Post date: [June 12, 2020, 11:59am UTC](https://forum.syncthing.net/t/help-scripting-with-rest-system-connections/15103/18 "2020-06-12T11:59:48Z")

</div>

I got rid off false positive connections (read unstable, spurious connected status) by tweaking my script this way (increased probes number to 4 and sleep in between to 17s - 17 instead of a multiple of 5 lowers the risks of regular sync between connections and probes), which gives enough time to the long ones among relay-client connections to drop or be replaced by higher rate and quicker failure-responsive new tcp-client ones. This seems the minimal tradeoff:

```
...
 # Counter for successive connections
while :; do echo `date +'%B %-d %T'` "AutoOff.sh (L24) enter wait for successive connections loop" &>>/var/log/syslog
 if [[`$REST/system/connections|awk -v HID=$HomeID '$0~HID,/}/ {if ($0~/connected/) print}'|grep '"connected": true,'`]]; then ((++CmptCntd)); echo `date +'%B %-d %T'` "AutoOff.sh (L25) ST connected. Increased counter by 1:" $CmptCntd &>>/var/log/syslog
    if [$CmptCntd -ge 4]; then echo `date +'%B %-d %T'` "AutoOff.sh (L26) ST connected threshold reached:" $CmptCntd ": so break" &>>/var/log/syslog; break 1
    fi; echo `date +'%B %-d %T'` "AutoOff.sh (L27) ST was sense connected for only (current count):" $CmptCntd " time. Sleep17 and continue" &>>/var/log/syslog; sleep 17; continue 1
 fi; echo `date +'%B %-d %T'` "AutoOff.sh (L28) Test connected failed. Counter:" $CmptCntd &>>/var/log/syslog; CmptCntd=0; echo `date +'%B %-d %T'` "AutoOff.sh (L28) counter was reset to:" $CmptCntd ". I will sleep15" &>>/var/log/syslog; sleep 15
done
echo `date +'%B %-d %T'` "AutoOff.sh (L30) exited loop" &>>/var/log/syslog
...
```

---

_[View the full topic](https://forum.syncthing.net/t/help-scripting-with-rest-system-connections/15103)._
