Watch a file for changes and copy/sync it to a remote host

entr

  • works on Linux and Mac OS
  • install entr
ls -b [file]... | entr -p scp /_ targethost:/destination/folder/

inotify

  • works only on Linux
  • it does not work if the file is replaced rather than changed.
  • install inotify-tools
F="filename" eval 'inotifywait -m -e close_write $F | while read E; do echo -e $(date +"%F %T") $E; scp $F root@targethost:/destination/folder/; done;'

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.