diff --git a/nextcloud/syncNC.sh b/nextcloud/syncNC.sh index c3bf588..7cd46a1 100755 --- a/nextcloud/syncNC.sh +++ b/nextcloud/syncNC.sh @@ -250,6 +250,20 @@ sync_all() { return 1 } +wait_for_nextcloud() { + for _ in {1..3}; do + if ! pgrep -x "nextcloudcmd" >/dev/null; then + return 0 + fi + + echo "Nextcloud sync is already active, waiting 20 seconds..." + sleep 20 + done + + echo "Nextcloud sync is still active after 3 retries, stopping." + return 1 +} + main() { parse_args "$@" validate_sync_options @@ -262,11 +276,7 @@ main() { die "Cannot read credentials file: $NETRC" fi - if pgrep -x "nextcloudcmd" >/dev/null; then - echo "Nextcloud sync is already active, stopping." - return 1 - fi - + wait_for_nextcloud echo "Starting Nextcloud synchronization..." sync_all