nextcloud / desktop

💻 Desktop sync client for Nextcloud
https://nextcloud.com/install/#install-clients
GNU General Public License v2.0
3.04k stars 797 forks source link

Check current sync status from command line #6345

Open fabianostermann opened 9 months ago

fabianostermann commented 9 months ago

Feature description

Hi all,

I am looking for a way to determine the current state of the nextcloud client (mainly: "syncing.." vs "all synced") in a bash script. I use that to wait for syncing to end and then automatically trigger shutdown. Dropbox, which I used for a long time, has a python script command for that: $ dropbox status That just returns a string, that can be captured and interpreted.

If there isn't such a functionality in the nextcloud client (and my searches indicate nothing useful), I would like to give it a try. For my use case, it could mean to just perform a hacky lookup of some log files (I saw I can enable logging to /tmp/Nextcloud-logdir/) or anything similar. So has anyone, who is more into the code, an idea how to cleverly approach this for now?

Also, I would suggest to consider such a utility a super enhancement for this project. If a simple approach could be found for now, I would like to look into integrating this to the project in a smoother way.

Thx in advance for any suggestions!


The information I want to obtain seems to be stored in src/common/syncfilestatus.h

What happened to nextcloudcmd? Is src/cmd working or not? Sorry, but I cannot find up-to-date information about it. Thx!

PhilippSchlesinger commented 9 months ago

Similar request https://github.com/nextcloud/desktop/issues/6328

fabianostermann commented 9 months ago

Good news. I came up with a quick solution! (Linux only)

I just borrowed some code from the syncstate nautilus-extension, which connects to a socket that communicates with the nextcloud client. With this approach, all information that the socket provides (see here for all the possible requests) can be implemented.

I mirrored the behavior of the Dropbox command-line tool that is to print Up to date or Syncing.. whenever called. I decided to do so (for now), because I used Dropbox before and can reuse all my personal scripts this way (e.g. delaying shutdown when some syncing has not yet finished).

I have made the python script available here.