Created
February 12, 2026 01:22
-
-
Save jdimpson/bff13840c35b976e7bc300bd00821c51 to your computer and use it in GitHub Desktop.
Shell script to invoke a callback when a new file is written to filesystem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| DIR="$1"; | |
| if test -z "$DIR"; then | |
| DIR="."; | |
| fi | |
| echo "Monitoring folder $DIR for new files"; | |
| RECSEP="|"; | |
| inotifywait -m -r --format "%w$RECSEP%e$RECSEP%f" -e 'CLOSE_WRITE,MOVED_TO' $DIR | \ | |
| (IFS="$RECSEP"; while read folder event file; do | |
| # put new file command / callback here. | |
| echo "new file $file in $folder ($event)"; | |
| done) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this to post new media (in the form of URLs) to Discord using webhooks.