Skip to content

Instantly share code, notes, and snippets.

@geekbrit
Created March 2, 2018 14:09
Show Gist options
  • Save geekbrit/a9e640bdd42e4f1d5f84997d1ee17127 to your computer and use it in GitHub Desktop.
Save geekbrit/a9e640bdd42e4f1d5f84997d1ee17127 to your computer and use it in GitHub Desktop.
BASH Daemon to watch for new image files, correct any rotation and resize within max dimensions
#!/bin/sh
#
# create watches for each subfolder within the specified location (1 level deep)
# renames the uploaded files to avoid infinite loop
#
for d in $(find /home/peter/Dropbox/MiniDonkies/Donkeys -maxdepth 1 -type d)
do
(
if [ '/home/peter/Dropbox/MiniDonkies/Donkeys' != $d ]; then
echo "$d"
inotifywait -m $d -e create -e moved_to |
while read path action file; do
echo "$path - $action - $file"
if [[ $file == *"jpg" ]] || [[ $file == *"JPG" ]]; then
mv $path$file "$path$file.JPEG"
jhead -autorot "$path$file.JPEG"
mogrify -resize 1200x1200 "$path$file.JPEG"
fi
done
fi
) &
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment