Check if sync is 100% on CLI


Recommended Posts

Hi all,

I just finished building my own dashcam with a Raspberry Pi. When I turn of the car at home, the Pi continues to run on own UPS and tries to connect to my wifi network. When connected, Resilio Sync (home edition) will sync the video folder to my NAS. When the sync is done, the Pi should be turned of.

Question is: how can I check from the Linux CLI if the sync is 100%? I noticed a log-entry in the sync.log with "UpdatePeersStat" and "FinishStateSync", but unfortunately looking for that entry doens't always work. 

Thanks in advance! :)


(ps. I've searched for this issue on the forum, but couldn't find an earlier question regarding this. If this is a duplicate question, mea culpa ;) )

Link to comment
Share on other sites

I think I've figured it out...

I stumbled on some strange behaviour of sync.log. Awk or a normal grep can't open the file sometimes. Awk replies nothing, grep replies "Binary file (standard input) matches". 🤔 I now know why my script was behaving erratically.

Using 'grep -a' circumvents this, I haven't found an awk equivalent yet. This enables me to sift through the output of the last five minutes. I can now quickly search for "ScheduledTask" messages. If the last one ends with "FinishStateSync", I assume Resilio sync is done and I can safely shutdown the Raspberry pi. 

Here's the code, but bear in mind the code is quite fugly 😎 Haven't had the time yet to turn it into a nice oneliner. Sorry for that...

    resilio_status=$(grep -Pzo '.*'"`date --date="-5 min" "+%Y%m%d %H:%M"`"'(.*\n)*' sync.log | awk '/ScheduledTask/&&!/ConnectMorePeers/'|  tail -n 1 | awk -F ":" '/UpdatePeersStat/{print $NF}')
    if [[ $resilio_status = 'FinishStateSync' ]];then
      # if so: write status, shutdown pi
      _pistatus | sudo tee ${report_dir}/pi_report_$(date +%FT%T)
      sleep 20
      echo " Resilio not yet finised"

    If anyone has a better  idea, don't hesitate to spam me 😁

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.