Skip to content

Instantly share code, notes, and snippets.

@terrymafura
Created December 4, 2019 17:11
Show Gist options
  • Save terrymafura/53d14e2bc0b52743c3c800d438f3f889 to your computer and use it in GitHub Desktop.
Save terrymafura/53d14e2bc0b52743c3c800d438f3f889 to your computer and use it in GitHub Desktop.
Bash script that waits for a file in a directory and processes it then zips
#!/bin/bash
TARGET=/<input_directory>
OUTPUT=/<output_directory>/
inotifywait -m -e create -e moved_to --format "%f" $TARGET \
| while read FILENAME
do
echo Detected $FILENAME, processing
# any instruction on the file here
mv "$TARGET/$FILENAME" "$PROCESSED/$FILENAME"
gzip "$OUTPUT/$FILENAME"
done
# Requires inotify-tools and gzip
# sudo apt install inotify-tools gzip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment