Skip to content

Instantly share code, notes, and snippets.

@hlapp
Last active January 2, 2018 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlapp/dbaa5baf2f6275887af2dba36b3dc167 to your computer and use it in GitHub Desktop.
Save hlapp/dbaa5baf2f6275887af2dba36b3dc167 to your computer and use it in GitHub Desktop.
Moves files from a source directory to a destination directory, one at a time, with a delay, which extends when the destination directory accumulates files. One use-case is feeding a large number of files into a spool directory where they get processed.
#!/bin/bash
set -e
src=${1:-.}
dest=$2
if [ -z "$dest" ] ; then
dest="$1"
fi
ls -f "$src" | \
while read f ; do
if [ -d "$src/$f" ] ; then
continue
fi
# echo "mv $src/$f $dest"
mv "$src/$f" "$dest"
sleep 3
spooled=$(ls -f "$dest" | wc -l)
if [ $spooled -gt 50 ] ; then
sleep 90
elif [ $spooled -gt 30 ] ; then
sleep 30
elif [ $spooled -gt 7 ] ; then
sleep 10
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment