#!/bin/bash inotifywait -m -r -e attrib -e create -e moved_to --format '%w%f' {{ sftp_root }} | while read file do current_permissions=$(stat -c %A "$file") if ! [[ "$current_permissions" =~ ^[^\ ](rw[^\ ]){2}[^\ ]{3}$ ]]; then # long: ^[^\ ]rw[^\ ]rw[^\ ][^\ ][^\ ][^\ ]$ matches "?rw?rw????" echo "Attribute change detected on $file" chmod u+rw,g+rw "$file" else echo "Skipped change for $file" fi done