Skip to content

Instantly share code, notes, and snippets.

@jdimpson
Created February 12, 2026 01:22
Show Gist options
  • Select an option

  • Save jdimpson/bff13840c35b976e7bc300bd00821c51 to your computer and use it in GitHub Desktop.

Select an option

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
#!/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)
@jdimpson
Copy link
Author

I use this to post new media (in the form of URLs) to Discord using webhooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment