Home Blog Tags Shell
Tags >> Shell
Feb 12
2010

Adding a startup script on Ubuntu server

Posted by: Marko Tomic

Tagged in: ubuntu , Shell , linux , command

This is a useful tip for my reference.  I've been creating some startup scripts on my Ubuntu server lately and her are a couple of steps required to get this working.

Write your startup script and place it in /etc/init.d/ directory. Let's say you called your startup script - myScript.  You then install your script by using update-rc.d debian utility:

update-rc.d myScript defaults

Have a look at man update-rc.d for more info.

And finally, you have to make your file executable:

chmod +x myScript

Nov 20
2009

Recursively remove .svn directories from your project

Posted by: Marko Tomic

Tagged in: SVN , Shell

Occasionally I find .svn directories in my old projects that are not in Subversion.  The quickest way to recursively remove them is to run the following command:

find . -name .svn -print0 | xargs -0 rm -rf

You need to cd into your project directory before running it.

You can also run the command to quickly disconnect your project from Subversion.

Nov 04
2009

SSH Tunneling - Add secondary address to your loopback interface HOWTO

Posted by: Marko Tomic

Tagged in: SSH , Shell , OS X

I'm writing this one for my own reference because almost everything I do for work, is done through SSH port forwarding. If you're not familiar with SSH port forwarding, you'll have to read up on it elsewhere. And the reason why we use SSH port forwarding is because it is secure and powerful.

I generally set up my port forwards to run on my local computer on an arbitrary port and configure SSH to create a proxy connection to the normal port on a remote computer. Then I configure my application to connect to my local computer on the chosen arbitrary port.

For example, I would create my virtual hosts in /etc/hosts:

sudo nano /etc/hosts

127.0.0.1 local1A.fwd
127.0.0.1 local1B.fwd
127.0.0.1 local1C.fwd

let's say I want to forward my local requests on ports 6800, 6801, 6802 to remote servers on ports 3012, 3013, 3014. Start by modifying your ssh config:

nano .ssh/config

add the following:

host remote1A
hostname 111.111.111.111 #remote IP address goes here
user my_username #server username goes here
localforward local1A.fwd:6800 111.111.111.111:3012

host remote1B
hostname 111.111.111.111 #remote IP address goes here
user my_username #server username goes here
localforward local1B.fwd:6801 111.111.111.111:3013

host remote1C
hostname 111.111.111.111 #remote IP address goes here
user my_username #server username goes here
localforward local1C.fwd:6802 111.111.111.111:3014

You should now be able to ssh to remote machines:

ssh remote1A

and similarly for 1B and 1C.

Now, lets say you want to create another 3 local hosts and simultaneously port forward to another 3 remote machines via exact same port numbers. This is where you'll run into problems, because you can only use one local port at a time on 127.0.0.1. The workaround it is to create secondary addresses to your loopback interface 127.0.0.2, 127.0.0.3 and so on. The command to add the secondary IP address is:

ifconfig lo0 alias 127.0.0.2/32

Now you can add new set of hosts:

127.0.0.2 local2A.fwd
127.0.0.2 local2B.fwd
127.0.0.2 local2C.fwd

And use the same set of port numbers to tunnel through another set of remote servers:

host remote2A
hostname 222.222.222.222 #remote IP address goes here
user my_username #server username goes here
localforward local1A.fwd:6800 222.222.222.222:3012

host remote2B
hostname 222.222.222.222 #remote IP address goes here
user my_username #server username goes here
localforward local1B.fwd:6801 222.222.222.222:3013

host remote2C
hostname 222.222.222.222 #remote IP address goes here
user my_username #server username goes here
localforward local1C.fwd:6802 222.222.222.222:3014

Marko

Stalk Me

Facebook: marko.tomic Twitter: mtomic Twitter: SydneyScuba YouTube: migonyourtail Linked In: tomicmarko MySpace: markomedia Google Wave: marko2009 blip.fm: markotomic

Site Login

Tag Cloud

Browser Poll

What browser do you use?