Created
July 10, 2012 18:06
-
-
Save jonatw/3085214 to your computer and use it in GitHub Desktop.
sync remote file
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=/tmp/ | |
dest=192.168.1.7 | |
/usr/bin/inotifywait -mrq --format '%w %w%f %e' -e attrib,modify,move,create,delete,close_write $src \ | |
| while read path files event | |
do | |
if [ "$event" == "MOVE_TO" ] || [ "$event" == "CREATE" ] || [ "$event" == "ATTRIB" ] || [ "$event" == "CLOSE_WRITE" ]; then | |
#just scp it | |
#echo $path | |
#echo $files $event | |
ssh root@$dest "mkdir -p $path" | |
scp -pq $files root@$dest:$path | |
fi | |
if [ "$event" == "DELETE" ] ; then | |
ssh root@$dest "rm $files" | |
fi | |
if [ "$event" == "DELETE,ISDIR" ] ; then | |
ssh root@$dest "rm -rf $files" | |
fi | |
if [ "$event" == "CREATE,ISDIR" ] ; then | |
ssh root@$dest "mkdir -p $files" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment