Skip to content

Instantly share code, notes, and snippets.

@greyltc
Last active August 20, 2017 12:01
Show Gist options
  • Save greyltc/dcfab85afb29bad4e476b973b2575315 to your computer and use it in GitHub Desktop.
Save greyltc/dcfab85afb29bad4e476b973b2575315 to your computer and use it in GitHub Desktop.
uses rsync to send all files in a directory except for the ones that are open
#!/usr/bin/env bash
#bash <(curl -L https://gist.github.com/greyltc/dcfab85afb29bad4e476b973b2575315/raw) $DEST
shopt -s nullglob
files=(*)
NOTOPEN=()
for i in "${!files[@]}"; do
if fuser -s "${files[$i]}" ; then
echo "${files[$i]} is open"
else
NOTOPEN+=(${files[$i]})
fi
done
echo "Sending ${NOTOPEN[@]}..."
rsync -av --remove-source-files ${NOTOPEN[@]} $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment