@rlpowell Your script looks like it serves a similar purpose as the wait-for-idle
command of my syncthingctl
utility. Here’s an excerpt from its --help
:
wait-for-idle, -w
waits until the specified dirs/devs are idling
--dir, -d [ID]
specifies the directories, default is all dirs
--dev [ID]
specifies the devices, default is all devs
--at-least, -a [number]
specifies for how many milliseconds Syncthing must idle (prevents exiting to early in case of flaky status)
--timeout, -t [number]
specifies how many milliseconds to wait at most
example: syncthingctl wait-for-idle --timeout 1800000 --at-least 5000 && systemctl poweroff
syncthingctl wait-for-idle --dir dir1 --dir dir2 --dev dev1 --dev dev2 --at-least 5000
The utility is using the event API Jakob mentioned.