Skip to content

RSNara/watch.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 

Repository files navigation

watch.js

This is a node.js script that watches local files and keeps them updated on a remote server. It requires node.js, rsync, and a server that allows password-less login via SSH keys.

watch.js source destination
   -i,    --identity=ARG        Specify id_rsa file location (default: `~/.ssh/id_rsa`).
   -t,    --time=ARG            The minimum time period between successive rsyncs (default: 250 ms).
   -d,    --delete              Delete extraneous files on the remote (dangerous).
   -h,    --help                Display this help.

Example Output:

On every file change, it'll perform an rsync:

> watch.js ../a3/ rsnara@linux.student.university.ca:/home/rsnara/cs240/a3
rsync #1 [SUCCESS]: ./, asm.cc, kind.cc, kind.h, lexer.cc, lexer.h, traverse.cc, old/, old/asm.cc
rsync #2 [SUCCESS]: asm.cc, kind.cc
rsync #3 [SUCCESS]: lexer.cc, traverse.cc, old/

Installation ============

Grab node.js and install Cygwin with rsync and ssh-keygen.

Once you have all three things installed, clone the repository and install the npm modules:

> git clone https://github.com/ramanpreetnara/watch.js.git path/to/repo
> cd path/to/repo && npm install

NOTE: You can also add path/to/repo into your PATH environment variable to make the script easier to execute.


Server Configuration: ====================

NOTE: To use this script, your server must allow password-less login via SSH Keys. If that's already set up, feel free skip this section.

We'll generate two files: id_rsa and id_rsa.pub using ssh-keygen.

# follow the instructions
> ssh-keygen

Now, append the contents of newly generated id_rsa.pub to the file ~/.ssh/authorized_keys on your server.

# copy over the file (fill in the details here)
> scp ~/.ssh/id_rsa.pub username@server:/temporary/location/id_rsa.pub

# SSH into the server
> ssh username@server

# append to ~/.ssh/authorized_keys
> echo '' >> ~/.ssh/authorized_keys
> cat /temporary/location/id_rsa.pub >> ~/.ssh/authorized_keys

To test to see if the key works, simply run watch.js source destination.

NOTE: You can also generate a private key using PuTTYgen and try to log in via PuTTY (using the private key). If the key doesn't work, feel free to post an issue (after doing some digging around on Google, that is).


Special thanks: ===============

This script builds on the following three node projects:

getopt - a command line parser that makes the script easier to run
node-rsync - building and executing rsync commands with Node.js.
async - async flow-control module for Node.js.

Notices:

This script relies on fs.watch, which is currently unstable.

About

A node.js script that automates rsync to trigger on filechanges.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published