Created
March 21, 2019 17:33
-
-
Save ejlevin1/c0cca7f82ac9cc206f50d88f18cd4c4c to your computer and use it in GitHub Desktop.
Script that copies files written to a specific folder to a different backup folder.
This file contains 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/bash | |
SRC_DIR=$1 | |
DST_DIR=$2 | |
if ! [ -d "$SRC_DIR" ]; then | |
echo "Directory specified to watch does not exist." | |
fi | |
if ! [ -d "$DST_DIR" ]; then | |
echo "Destination directory specified does not exist." | |
fi | |
echo "Waiting to backup new files from [$SRC_DIR] to [$DST_DIR]." | |
inotifywait -m $SRC_DIR -e close_write | | |
while read path action file; do | |
if [ 'CLOSE_WRITE,CLOSE' = "$action" ] ; then | |
echo "Backing up new file: $file" | |
cp -vf "$path/$file" "$DST_DIR/$file" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment