Archive for ‘Tutorial’ Category

SSH Tunneling to mysql server using Putty

datePosted on 12:55, September 25th, 2008 by Many Ayromlou

 I’ve had this question a couple of times in the past few months (since I posted the command line version of this method here ). To make it short and sweet, yes you can use Putty in a windows environment to setup ssh tunnels. Here is the specific scenario with pics for setting up a tunnel to your mysql server (assuming mysql server is running on a machine that you have ssh access to) using putty. This allows you to run mysql-gui-tools under windows and connect thru ssh to your server, without having to open the server to accept connections from the network.

  1. Download Putty full install package 
  2. Run putty and your’ll see the following screen. Fill in the hostname of the DB server and choose SSH as protocol.
  3. Go down to SSH and Tunnels options. Fill in 3306 for Source port, 127.0.0.1:3306 for local Destination port and click Add. This will forward (through SSH) all traffic sent to 127.0.0.1:3306 (aka. localhost:3306) to the remote host’s (DB Server) port 3306. You’ll see how this works in a second.
  4. Now go back to Sessions, Give the session a meaningful name (eg: MYSQLTunnel) and click Save so that it’s saved.

So now you’re done. If you need to access your mysql server, first run putty, load the session we just saved, connect and you’re good to go. You can use any network based mysql frontend and even the ODBC connector under windows and point them at host: 127.0.0.1 and port: 3306, the SSH tunnel will then take the traffic and safely transfer it to your mysql server box. This way you can run your mysql server in local mode — where it will not accept connections from outside network — for safety reasons and have network access to it when you need.

Vista Network Blues…Repeated network disconnect

datePosted on 16:15, May 7th, 2008 by Many Ayromlou

A lot of people seem to be running into weird network problems with Vista (MS’s latest abortion). The symptoms might include:

– Windows messenger issues (disconnects, slowness)
– Large network file copies get interrupted or are slowwwww
– Network file transfers that seem to hang for no reason
– Network ghosts turning on/off the network subsystem
– Routers having issues that lead to router reboot
– Outlook having synchronization issues

A possible solution is turning off auto-tuning. You see Vista being Vista, wants to always be in control, even when it gets on the network with others. MS has built a new feature into it’s network stack that allows Vista to auto-tune the size of the send/receive windows…..why would you want to do this by default when half the worlds firewalls discard non-standard packet sizes is a mystery (apparently only known to MS ppl). So guess what happens when the firewall downstream of you decides that your packets are “non-standard”……it drops them, along with your connection. So how do you fix this, simple, you do what MS should have done before they shipped you the abortion called Vista, you disable it. Here is how:

1) Get a command prompt in administrator mode. To do this go to Start/All Programs/Accessories and RIGHT CLICK on command prompt’s icon and choose “Run as Administrator”. On the next prompt press “Continue”.
2) Make sure the Title of the newly opened command prompt window says “Administrator: Command Prompt”, if not go back to 1).
3) Now type the following into the command prompt window. This will disable autotuning.
netsh int tcp set global autotuninglevel=disabled
4) You should get a OK. in the command prompt window. REBOOT NOW.
5) If you need to turn it back on (why?) do the 1) and 2) and issue the following command
netsh int tcp set global autotuninglevel=normal
To check the status of this dumb setting (before or after you change it) do 1) and 2) and type the following command
netsh int tcp show global
Of course you could always reboot, format and install Linux and save your sanity and time :-)

Stripes be gone…..

datePosted on 22:26, November 1st, 2007 by Many Ayromlou

If you like to get rid of the stripes in the list view of the new Leopard Finder, open a Terminal Window and type in the following two commands:defaults write com.apple.finder FXListViewStripes -bool FALSE
killall Finder

If you want the fancy stripes back at some point later, type the following two commands in Terminal:defaults write com.apple.finder FXListViewStripes -bool TRUE
killall Finder
more to come soon…..

Turn-off Leopards 3D Dock

datePosted on 22:57, October 29th, 2007 by Many Ayromlou

Just noticed that if you place your dock on either side of the screen you get a flat dock, instead of that floating 3d look. As much as I like the 3D look, I liked the flat look even more, so after poking around I found out how to disable the 3D look. Open a Terminal window and type in the following two commands:
defaults write com.apple.dock no-glass -boolean YES
killall Dock

To get the 3D floating dock back you open a Terminal and type the “opposite” two commands:
defaults write com.apple.dock no-glass -boolean NO
killall Dock

Keep coming back…..there will be more soon :-)

Okay so this all started with our users not being able to share files on our webserver. We use SSH only for upload/download and interactive access (ie: no ftp). Through trial and error we found out that the default umask (under OSX Server) for sftp uploaded files are 0033 (ie: rwxr–r–) and directories are 0022 (ie: rwxr-xr-x). This creates a problem when one user uploads a file and another user downloads/modifies and tries to re-upload it — they simply can’t because the group permissions are wrong.

If we were using ftp (which we are not) there are some solutions on the net that allow you to modify the startup parameters for the ftp server so that the default umask for all files is 0013 — which would allow a group of people to share/overwrite each others files — but we are using ssh only.

So we came up with two other solutions — a shared upload account and/or a cron job that would modify the group permissions on the website directory to allow group sharing. We went with the second solution and that’s where I ran into so many problems that I decided to create this post. You see normally Unix users know that spaces (and strange characters) in filenames are a no-no. Well that’s not true for Windows and Mac users, they use spaces and other odd characters in their filenames/folders all the time.

I started writing — what I thought was — a simple “for loop” script to go through the website folder and change the group permissions. Of course on the first try things didn’t work nicely because of spaces, so I started compensating for that and came up with:
for i in `find /Path/to/www -type d -print0 |xargs -0 -n 1`
This kinda worked, but the for loop would still split the lines when it hit spaces in filenames. I tried to mess around with it and gave up. After RTFMing a bit more I tried:
for i in `find /Path/to/www -type d -exec echo \"{}\" \;`
The thinking behind this was that the exec would echo the filenames quoted and it should work….well it didn’t, the for loop still split the input lines at spaces.

Finally after a latenight RTFM session (and lots of cursing), I think I’ve found the ultimate file handling loop statement:
find /Path/to/www -type d ! -perm -g=wx -print0 | while IFS= read -rd $'\0' filename
Okay so this version uses “while” rather than “for” but it works like a charm and chews through spaces and all other kinds of weird chars and creates a output stream that’s ready to be used by your choice of commands (chmod in my case).

After trimming and optimizing the script a bit, here is the final product:
# The following find will search for
# all files under /Path/to/www, that
# are NOT symlinks, and do NOT have
# group write permission. The list is
# "\0" seperated and the while portion
# will loop around this character and
# ignore everything else in the path.
find /Path/to/www ! -type l ! -perm -g=w -print0 | while IFS= read -rd $'\0' filename
do
# We've found a directory with no group
# write permission, so fix it.
if [ -d "$filename" ]then
chmod g+rwx "$filename"
# echo Directory changed
stat -l "$filename"
fi
# We've found a file with no group
# write permission, so fix it.
if [ -f "$filename" ]then
chmod g+rw "$filename"
# echo File changed
stat -l "$filename"
fi
done

Hopefully you’ll find this code (or portions of it) useful for your own day-to-day hack-and-slash solutions to annoying problems. Let me know if you come up with an even better solution :-)

screen…it’s not just for nerds anymore.

datePosted on 20:26, October 7th, 2007 by Many Ayromlou

So after hearing from people at work how great the “screen” command was (yeah welcome to gnuland boys and girls), I decided to do a short tutorial on screen. This way I can stop telling them to RTFM and instead tell them to RTFB (Blog). Anyways, What is “screen” first of all….From the pages of wikipedia:

GNU Screen is a free terminal multiplexer developed by the GNU Project. It allows a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. It is useful for dealing with multiple programs from the command line, and for separating programs from the shell that started the program. GNU Screen can be thought of as a text version of graphical window managers, or as a way of putting virtual terminals into any login session. It is a wrapper that allows multiple text programs to run at the same time, and provides features that allow the user to use the programs within a single interface productively.

Think of screen as a Virtual Machine (I know it’s not but bear with me). Once you run the command, the ‘virtual machine’ takes over and allows you to create multiple interactive command line sessions. In each of those sessions you can run commands that are either interactive (menu based) or serialized. Once you’re done you can disconnect the session — keeping in mind that the session is actually alive and running, including all the programs that were spawned inside that session — go to another computer and ‘restore’ the session with all the programs still running. By far one of the coolest things about screen is that it automatically allows you to nohup your commands, by just disconnecting the session and reconnecting to it later. So without any further due here is screen:

Obviously you need to run it, so first step is to type screen at the command line. When you do that you get a new shell window and the adventure starts. Remember that pretty much all screen commands start with Ctrl-a followed usually by a character (ie: you press Ctrl button and c together, let go, and follow it with the character).

So now you have a new shell, run a command (ie: pine, vi or something). Okay so now we can simulate you leaving your machine and detaching your session.

– To Detach : Ctrl-a d (this will detach the session but your command is still running inside that screens shell….you’ll see)
– To Reattach : screen -r (without the quotes. You should get the session back with whatever command you were running in it).

So now you’ve got the very basics of screen. Detaching allows you to run commands, leave them halfway, detach and go somewhere else and use Re-attach to restore the session.

Now, how about multiple sessions. Yeah you can do that too, one screen process with multiple sessions inside it.

– Use screen -r to reattach to your process (If you haven’t done so already). Note that your program is still running (say vi). If you now want to run lynx for example you can use the Ctrl-a c command to create another session (c for create). So now you have two sessions inside your “screen virtual machine”.
– Use Ctrl-a n and Ctrl-a p to flip between sessions (n for next and p for previous). You can also create more screens with Ctrl-a c. Lets create 2-3 more sessions.
– Use Ctrl-a followed by a number between 0-9 to switch between up to 10 recently created sessions.
– Now use Ctrl-a d to detach from the session, logoff (don’t reboot, that will kill the screen process) and log back in. Now reattach to the process using screen -r. Note that all your sessions are still there (you can check using Ctrl-a n and Ctrl-a p to cycle through the sessions).

One last thing before I take away the training wheels, to kill your screen process (and all sessions running inside it) use Ctrl-a Ctrl-\.

Okay, so here is a small list of the many screen options and commands:

Ctrl-a “ : gives you a full screen list of all your sessions and you can scroll down to the one you want to switch to and press Enter (remember to get you have to use Shift-‘ and ESC gets you out of the list).
Ctrl-a A : (that’s a shift-a) allows you to give a meaningful name to your session window.
Ctrl-a k : allows you to kill your current session (not all sessions spawned inside a screen process, just the current session).
Ctrl-a S : will split your current session screen in half. It is easy to confuse Ctrl-a S, which uses a capital ‘S’ with Ctrl-a s, which uses a lower case ‘s’. The upper case command causes screen to be vertically split (that is, with one region on top of the other), while the lower case command causes the parent terminal to freeze (Scroll Lock). To unfreeze the parent terminal, use the Ctrl-a q command.
Ctrl-a : will jump between the regions in a split session. Keep in mind that the new region will have nothing in it until you designate another open session to pop in there using Ctrl-a p and/or Ctrl-a n which will cycle the next or previous session into the new split region.
Ctrl-a X : (that’s a shift-x) will close a region (ie: split region goes back to full).
Ctrl-a + : will enlarge the current region (and shrink the other).
Ctrl-a – : will shrink the current region (and enlarge the other).
Ctrl-a M : (that’s a shift-m) allows you to monitor the current window for output. I use the MSN command line client pebrot occasionally, and always set its window to notify me when something happens (ie: a join message).
Ctrl-a _ : does the same thing as above, but in a opposite way. It switches into the monitoring mode for 15 seconds of silence, which triggers a notification in xterm’s status area. So when our compile finishes, we will be told so even in another session.
Ctrl-a [ : will place you in copy mode. Use this when you need to copy some text from one session to another. Do Ctrl-a [ in the source session to enter copy mode (you can exit copy mode using ESC). Move around using cursor keys to the beginning of where you want to start copying and press Spacebar to mark the beginning. Now move to the end and press Spacebar again to mark the end of your copy block. You can now switch to another session, move to where you want to paste the block and press Ctrl-a ] to paste what was put in the buffer.

Here are a couple of more useful startup screen commands:

screen -ls : will list all the screen processes running under your userid (yes you can run multiple screen processes with multiple sessions inside each).
screen -r screenname : restores a specific screen process.
screen -R : will try to reattach if there is a detached process, if not it will start a new process.
screen -D -RR : this is the “I want control now” command. It will detach already attached clients and attach to the first session listed.

As usual screen is controlled via .screenrc file for configuration parameters (there is a system wide file in /etc/screenrc and the personal one in your home directory, under ~/.screenrc). You can add the following commands in your personal .screenrc to make life a bit simpler:

#kill startup message
startup_message off
# define a bigger scrollback, default is 100 lines
defscrollback 1024
# An alternative hardstatus to display a bar at the bottom listing the
# windownames and highlighting the current windowname in blue. (This is only
# enabled if there is no hardstatus setting for your terminal)
hardstatus on
hardstatus alwayslastline
#hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "
#hardstatus string "%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= mK}%+Lw%< %{= kG}%-=%D %d %M %Y %c:%s%{-}"
#hardstatus string "%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}"
#hardstatus string "%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]"
hardstatus string "%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]%{=b C}[ %m/%d %c ]%{W}"

As usual there is a lot more to screen, so once you’ve got the basics nailed, take a peek at the man pages for more goodies and don’t forget…..Command line is your friend :-).

Do you Mango?

datePosted on 13:15, September 23rd, 2007 by Many Ayromlou

From the pages of really useful, well designed websites comes Mango. The webapp (flash 9.0) is simple to use, well layed out and generally works well. It offers 11 Free language courses (Brazilian Portuguese, Polish, Spanish, French, German, Greek, Italian, Japanese, Mandarin Chinese, Pig Latin and Russian). So head over, sign up and learn something new. It’s FREE!!!

Track your Car using GPS/GSM gizmo…..

datePosted on 05:25, August 23rd, 2007 by Many Ayromlou


For all the people who dreamed about being able to track their vehicles by just sending SMS messages to their car, here is an article on Developing a vehicle tracker with the Telit GM862-GPS module. Great article that goes into a lot of detail on how you too can accomplish this.

How does the mouse pointer work…

datePosted on 11:01, June 2nd, 2007 by Many Ayromlou

Yeah, you heard right, I’m gonna show you how the mouse pointer on your computer really works. To do this we have to zoom in a portion of the screen. When you move to the next page, move the mouse to the centre of your screen and have a look. Also try clicking your mouse button. Now you know the secret…You are a true NERD :-)

12Previous