Skip to content

Instantly share code, notes, and snippets.

@rreece
Created June 27, 2018 18:34
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 rreece/760f50b5caa22afaad150393a1f2c67d to your computer and use it in GitHub Desktop.
Save rreece/760f50b5caa22afaad150393a1f2c67d to your computer and use it in GitHub Desktop.
Bash script to continuously watch for output files and move them
#!/usr/bin/env bash
log=mv_files.log
spare=/spare/ryan
dest=/cb/data/imagenet1k2/new/
while true; do
if test -n "$(shopt -s nullglob; echo $spare/*)"
then
echo "Moving files to $dest"
echo "Moving files to $dest" >> $log
ls -rt1 $spare | head -n -10 | xargs -n 1 echo
ls -rt1 $spare | head -n -10 | xargs -n 1 echo >> $log
ls -rt1 $spare | head -n -10 | xargs -I {} mv $spare/{} $dest
else
echo "$spare is empty"
echo "$spare is empty" >> $log
fi
echo "Sleeping..."
echo "Sleeping..." >> $log
sleep 1800 ## 1800 s = 30 mins
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment