wait-and-date.sh
#!/bin/bash WATCH_DIR="/home/grant/bucket" DATED_DIR="${WATCH_DIR}/dated" inotifywait --quiet --monitor \ --event CLOSE_WRITE --format '%f' $WATCH_DIR \ | while read FILE do DATE=$( sed -n -e 's/^ *>Report generated: \(.*\)<.*/\1/p' \ "${WATCH_DIR}/${FILE}" ) ISO_DATE=$(date --date "${DATE}" +%F) mv "${WATCH_DIR}/${FILE}" \ "${DATED_DIR}/staging-changelog-${ISO_DATE}.html" echo "Saved: ${DATED_DIR}/staging-changelog-${ISO_DATE}.html" done