Archive

Posts Tagged ‘Terminal’

Set Up An rsync Server in Ubuntu for File Syncing Between Machines

January 19, 2009 21 comments

I’ve been doing some programming on my laptop recently and then finding myself without my work when I’m on my desktop.  I remembered someone telling me that they use rsync to keep their source directories in-sync between their home and work machines, so I figured I’d do the same.

I thought it would be trivial to accomplish a file transfer using rsync between 2 machines on a local network, but I ended up spending an hour more than I wanted to.

So, first of all you need to have rsync on both machines (the server and the client).  In my situation, I’m running Ubuntu 8.04 LTS on my desktop and Windows XP w/ Cygwin on my laptop; rsync comes pre-installed in Ubuntu and as an install option in Cygwin.

If you’ve already got Cygwin but rsync is not installed, you need to run the Cygwin setup.exe again. Then, rsync will be under the Net directory in the package choosing menu.

On the server machine you need to set up a daemon to run in the background and host the rsync services. First – before you start the daemon – you need to create an rsync daemon configuration file. To do this in Ubuntu, create a file named rsyncd.conf in the /etc directory, i.e.

you@your-computer:~$ sudo gedit /etc/rsyncd.conf

Now enter the following information into the rsyncd.conf file:

motd file = /etc/rsyncd.motd

[workspace]
path = /home/username/workspace
comment = This is the path to my Eclipse workspace (on the server)
uid = username
gid = username
read only = false
auth users = username
secrets file = /etc/rsyncd.scrt

Now replace all occurrences of username with your username on your server (not the username on your client machine!). Since I set this up for keeping my Eclipse workspaces in-sync, I used “workspace” for the path name, but you can use anything (so change “[workspace]” to “[whatever_you_want]”). I also set the path equal to my Eclipse workspace, but once again, this path can go anywhere you want to sync your files to.

Notice there are two other files mentioned: /etc/rsyncd.motd and /etc/rsyncd.scrt. You need to create these the same way you created the /etc/rsyncd.conf file.

The /etc/rsyncd.motd is the Message Of The Day file. The contents of this file will be displayed by the server when a client machine connects.

The /etc/rsyncd.scrt file contains username and password pairs. For example,

username:whatever_password_you_want

As before, username should be your username on your server.

Now you should have all the configuration information necessary, all that’s left to do is open the rsync port and start the daemon.

To open the port, open the /etc/default/rsync file, i.e.,

you@your-computer:~$ sudo gedit /etc/default/rsync

and set RSYNC_ENABLE=true.

Now to start the daemon,

you@your-computer:~$ sudo /etc/init.d/rsync restart

There you have it, your rsync server should be up and running!


Now you probably want to know how to copy files from your remote machine to your server. In Cygwin,

$ rsync -vr SRC username@server ip-address::workspace/DEST

The -vr flags are for verbose output and recursive (so entire directory structures can be copied). The SRC is the root directory of your source files. If you wanted to sync your entire Eclipse workspace with the workspace on your server, this would be the workspace directory; the recursive flag would then go through all the projects within your workspace directory and copy everything. The username should match the username in the /etc/rsyncd.conf file. The “workspace” after “::” should match your path name in the /etc/rsyncd.conf file, i.e., the “[workspace]”. DEST is then appended to the path from the /etc/rsyncd.conf file, i.e., /home/username/workspace/DEST.

When you enter this command you should see the contents of the /etc/rsyncd.motd file appear and you should be prompted for the password corresponding to the username provided. This username/password pair should match the contents of the /etc/rsyncd.scrt file. Once you enter the password correctly, the sync will begin!


Here’s an example with the username on the server “nick” and the server ip-address is “192.168.0.8”:

/etc/rsyncd.conf:

motd file = /etc/rsyncd.motd

[workspace]
path = /home/nick/workspace
comment = My Eclipse workspace directory.
uid = nick
gid = nick
read only = false
auth users = nick
secrets file = /etc/rsyncd.scrt

/etc/rsyncd.motd:

Welcome to my rsync server!

/etc/rsyncd.scrt:

nick:mybirthday

To sync the “Java2D” projects in the workspaces of the server and client machines (entered in Cygwin on client/remote machine):

$ rsync -vr /Documents and Settings/Nick/workspace/Java2D/ nick@192.168.0.8::workspace/Java2D
Welcome to my rsync server!

Password: mybirthday

Categories: Linux Tags: ,

Note-Taking in the Terminal

November 3, 2008 1 comment

sticky_note_id_by_choujiswirlz
Given that the terminal is a productive environment and notes are productive objects, putting the two together can yield productive environment-objects…err, notes in the terminal.  The first day I got my Linux machine I set this handy tool up – since the notes are in a text file and you’re in terminal, you can use all sorts of text-related command-line tools to search your notes.

To begin, you’ll need to make a basic text file somewhere on your machine, preferably in the directory that your terminal opens to.  No need to figure out where that is exactly, simply open your terminal and create the file, i.e.

you@your-computer:~$ touch notes

Now you should see an empty file named “notes” in your home directory.

Here are 2 ways to write notes to the file.  The first way is easier if your note is small enough:

you@your-computer:~$ echo “this is a note” >> notes

Your note goes within the quotes, and at the end the text is appended to the end of the notes file.


BE CAREFUL!

Be sure to use the double arrows >> instead of a single arrow > or you will erase all your previous notes!

The >> means to append the text to the end, where the > means to replace the entire file with the text.


The second way is more interactive and is best used for entering multiple notes or long notes:

you@your-computer:~$ cat >> notes

This will move your cursor to the next line and wait for input.  Simply start typing the note – hitting Enter will move you to the next line.

  • To save and finish entering notes, hit Ctrl-d
  • To abort, hit Ctrl-c
  • To cut text from cursor to end of line, hit Ctrl-k
  • To paste text at cursor, hit Ctrl-y

It’s a good idea to pre-pend each note with a topic/category/tag name so they’re easy to find with grep.  For example, say you’re entering some notes on terminal keystrokes, then your notes would look like:

terminal keystrokes: Ctrl-d to finish

terminal keystrokes: Ctrl-c to abort

Now to find all of your notes on keystrokes:

you@your-computer:~$ cat notes | grep keystrokes

And the output would be:

terminal keystrokes: Ctrl-d to finish

terminal keystrokes: Ctrl-c to abort


Now remember to use those productive environment-objects!

Got a better way to take notes with the terminal?  Share it in a comment.

Categories: Linux Tags: , ,

Relive the Classic! Watch Star Wars Through Your Terminal!

October 28, 2008 Leave a comment

Here’s an odd find – watching Star Wars: A New Hope (the first original) in ASCII art through your command-line terminal.

Yes, ASCII art, like Kirby: <(‘-‘<) (>’-‘)> and my favorites: t(‘-‘ t) (flip-you-off Kirby) and Q(‘-‘Q) (boxing Kirby).

Anyways, to watch the movie you need telnet, so you Cygwin users make sure you’ve got it. Those linux users should already have it.

To start the magic, type in your terminal: telnet towel.blinkenlights.nl

And if you manage to watch the whole thing, come back and let me know how it ends.