Not a lot of rainbow in this one. This is a pretty dry, but useful tutorial. In a recent conversation with my good friend Nick Matterson about effective web development tools, the topic of getting files onto a server came up. A lot of people use GUI tools, while others do command line stuff. This tutorial is purely command line (i.e. Mac’s Terminal), and after a few short lines of code results in a website that is automatically mirrored to a local folder, updating in 1 minute increments via a crontab.

The process happens in a few basic steps:

* Establish a security key connection for ssh. This is useful beyond this trick if you ever want to login without a password. Here is a more detailed link, but the process is simple. Generate a key on the local machine via:

ssh-keygen -t rsa

Leave the fields blank, if a key already exists don’t overwrite it. Now, just like in the link:

cat /Users/rasmussj/.ssh/id_rsa | ssh username@IPADDRESS ‘cat >> .ssh/authorized_keys’

This puts the key on the remote host so I no longer need a password.

* Now that I can do that, the rsync command can sync the two folders. Without it you just have to enter in your password every time (which is why it won;t work with crontab). Here is the syntax I used to sync the folders in ~/Desktop/Homepage to /www/jerodweb on my web server (A Small Orange).

rsync ~/Desktop/Homepage/* username@IPADDRESS:/www/jerodweb/

* So easy! Now the last step is to create a crontab to do however frequently you wish, at the command line do

crontab -e

And then using your default editor you’ll be able to put the rsync line from above into a cronjob using this syntax.

0 * * * * rsync ~/Desktop/Homepage/* username@IPADDRESS:/www/jerodweb/

This will get the update done hourly, but you can easily change that to every minute. Super easy and you’ll never have to worry about syncing again. Also super boring too though… hope it helps Nick! Coda is great by the way.

Advertisements