Skip to content

Instantly share code, notes, and snippets.

@aimfireready
Created October 21, 2022 14:50
Show Gist options
  • Select an option

  • Save aimfireready/330f4c631dc17cf88dc334d74d036a29 to your computer and use it in GitHub Desktop.

Select an option

Save aimfireready/330f4c631dc17cf88dc334d74d036a29 to your computer and use it in GitHub Desktop.
Watch for new files in Motioneye directory and upload them to a shared Nextcloud folder.
# v1.0.0
# 2022 Gandalf Farnam
# Watch for new files in Motioneye directory and upload them to a shared Nextcloud folder.
#
# Specific parameters for inotifywait:
# --event create = only created files. This includes files copied to the target directory
# --exclude .*thumb$ = any files except thumbnails
# -r including subdirectories
#
# Specific parameters for curl:
# -k for insecure connections (crutch)
# -u
#
# Usage:
# - Replace $USER with the shared folder token.*
# - Replace $URL with your domain.
# *Cf. Nextcloud forum to get the $USER string: https://help.nextcloud.com/t/upload-to-file-drop-using-curl-from-command-line/11893/5
while newfile=$(inotifywait -q --event create --format '%w%f' --exclude .*thumb$ -r /var/lib/motioneye/); do
curl -k -T $newfile -u '$USER:' -X PUT https://$URL/public.php/webdav/$newfile;
done
# Most helpful online resources on this topic:
# https://askubuntu.com/questions/819265/bash-script-to-monitor-file-change-and-execute-command
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment