how do I modify the
inotifywaitcommand to report only when a file of certain type/extension is created
Please delete my profile as requestednote that this is untested code since I don't have access to inotify right now. But something akin to this ought to work with bash:
inotifywait -m /path -e create -e moved_to |
while read -r directory action file; do
if [[ "$file" =~ .*xml$ ]]; then # Does the file end with .xml?
echo "xml file" # If so, do your thing here!
fi
done
Alternatively, without bash,
inotifywait -m /path -e create -e moved_to |
while read -r directory action file; do
case "$file" in
(*.xml)
echo "xml file" # Do your thing here!
;;
esac
fi
done
With newer versions of inotifywait you can directly create a pattern match for files:
inotifywait -m /path -e create -e moved_to --include '.*\.xml$' |
while read -r directory action file; do
echo "xml file" # Do your thing here!
done