Archive for the ‘HOWTO’ Category

HOW TO : More examples of grep

Wednesday, May 6th, 2009

For my reference.. good article about command line usage of grep . http://arstechnica.com/open-source/news/2009/05/command-line-made-easy-five-simple-recipes-for-grep.ars . Older how to articles on my site related to this topic are here and here.

HOW TO : Setup SOCKS proxy using SSH/Putty and configure Pidgin to use SOCKS proxy

Friday, April 10th, 2009

I ran into a challenge  recently, when I tried to connect to my IM services (Yahoo, MSN, AOL, GTalk) using Pidgin in a secured network. For some reason, the network administrator thought that he/she should make life hell for people trying to log into IM. I will have a whole new rant about companies trying to lock down networks thinking they are making the employees productive..

Here’s what I did to connect to my IM services.

  1. Configure Putty/SSH to act as a SOCKS proxy.
    • Most people might not be aware, but a typical SSH client can act as a SOCKS proxy. So I decided to leverage this functionality.
    • You will need access to a SSH server and Putty (Opensource Windows SSH client)
    • Launch Putty
    • Setup a new server connection profile. I used FREE_MY_IP as the profile name in this screen shot, but you can name it anything you want

    • Expand the SSH option in the left column and click on Tunnels
    • Choose any port higher than 1024 as source port (unless you are running some kind of server software on your workstation, it is safe to use any port above 8000) and enter the SSH server in the Destination field. Then choose the “Dynamic” option and click on Add.. the screen shot below shows the options I used

    • The tunnel will show up as below

    • Click on Open and establish the SSH tunnel
  1. Configure Pidgin (open source IM client) to use the SOCKS proxy
    • Launch Pidgin
    • Click on Tools -> Preferences in the menu
    • Click on the network tab
    • Choose SOCKS4 as the proxy type and enter localhost in the host field. In the port field enter the port you selected when setting up the tunnel in Putty.

  1. Connect to your IM services.. chat away and be unproductive :)

HOW TO : Force expire sudo security permissions..

Thursday, March 26th, 2009

Ever run into a situation when you thought you had sudo rights on a machine and tried to issue the sudo command and upon finding that you don’t have them..get your name added to the sudoers list by begging the sysadmin.. and then frusrated when sudo keeps throwing an error that you are not part of the sudoers list? Hmm.. that is a long sentance :) ..

To expire any cached security permissions, so that sudo is forced to check the sudoers files, issue the following command

sudo -k

HOW TO : Simple perl script to replace lines in file

Thursday, February 19th, 2009

Nothing fancy.. but here is a simple perl script to open a file, search for specific content in the a line and replace it with some other content.

open (SOURCE, "< source.xml")
or die "Could not open file source.xml: $!\n";

open (DESTINATION, ">modfile.xml")
or die "Could not open file modfile.xml: $!\n";

while (defined($line = )) {
if ($line =~ m/YYYYYYYY/i) {
$line = "XXXXXXXXXXXXXXXXXXX\n";
}
print DESTINATION "$line";
}

close (SOURCE);
close (DESTINATION);

You are opening a file named source.xml, reading every line and if there is some text that matches “YYYYYYYY”, you are replacing the whole line with “XXXXXXXXXXXXXXXXXXX”. I am sure there are more elegant ways to write this :) .. but this will do the trick too..

HOW TO : Spice up your digital pictures..

Friday, February 13th, 2009
  • Go to http://www.befunky.com
  • Upload, grab a picture
  • Play with different options
  • Save, Print, Enjoy :)  (you can print the manipulated pictures on mugs, t-shirts, keychains, magnets etc..).

Here’s an example

ORIGINAL

AFTER PLAYING AROUND IN BEFUNKY

HOW TO : View HTML pages in Linux (command line)

Friday, January 30th, 2009

If you are stuck in a terminal on a Linux workstation and need to view a html file.. you can use the following command

links NAME_OF_HTML_FILE

Links displays the HTML code in the page by default..If you want to just view the rendered HTML, press “\” and you can toggle between HTML and Text views.

P.S : You need to have links installed to use it :) .. But most of the new distributions have it installed by default.

HOW TO : Delete duplicate lines in Linux/Unix

Thursday, January 22nd, 2009

If you have a large text file and want to quickly delete any duplicate lines, you can use the following option of sort in *nix..

sort -u filename > newfilename

If you want to get even funkier :) , like only checking duplicates on a particular column, feel free to check out this link http://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html#sort-invocation.

HOW TO : Microsoft Windows – Routing to /dev/null

Wednesday, January 21st, 2009

Ran into an interesting issue at work today and wanted to document it. We had a rouge process in one of our applicatoins and it was trying to send e-mails via one of our mail gateways at an alarming rate..There was no customer impact, since the mail server was rejecting all the connections. But the high number of connections were causing a strain on our firewalls..

If this was Linux, we would have done something simple like adding a route to point all the traffic destined to mail server to /dev/null by running “route add IP_ADDRESS_OF_MAIL_SERVER MASK /dev/null

A search on Google showed that you can achieve similar results by doing the following “route ADD IP_ADDRESS_OF_MAIL_SERVER MASK 255.255.255.255 127.0.0.1“. 127.0.0.1 being the IP address of the loopback interface in this case. But when we ran the command, we got an error “incorrect gateway 127.0.0.1″.. So there is NO way to route traffic in Microsoft Windows to a null device..

Finaly, we figured out a round about way to achieve this.. Since the main aim was to reduce the load on the firewall, we identifid an un used IP in the same network as the application server and added a static route to point all traffic going to the mail server to this IP. We ran the following command “route ADD IP_ADDRESS_OF_MAIL_SERVER MASK 255.255.255.255 UN_USED_IP_ADDRESS

For example, if you application server is in the range 192.168.1.0/24, the mail server is 192.168.2.20.. and an unused IP in the application server range is 192.168.1.10.. the command would look like this “route ADD 192.168.2.20 MASK 255.255.255.255 192.168.1.10“.. You will see a lot of SYN_SENT status in the network connections, since the application is trying to connect t othe mail server via an IP address that doesn’t exist..

Might not be the smartest way to achive this.. but it did the trick.

HOW TO : Configure AT&T 3G on Windows Vista without Communication Manager

Thursday, January 8th, 2009

This is a howto for the geek in you :-) . You can easily configure a AT&T 3G Wireless card on your workstation using the Communication Manager software provided by AT&T.. But then I have always been against using bloated software for something you can configure on your own.

I recently got a 3G card at work and needed to install it on my laptop. I figured that the AT&T  provided software was just setting up a dial-up connection with specific settings. Guessing that some Linux geek might have already figured out what the settings where, I used the following search term in Google “Linux Ubuntu Configure AT&T 3G card”.. Lo and behold, the following link showed up http://redmonk.com/sogrady/2008/12/07/how-to-use-an-att-ericsson-f3507g-card-on-ubuntu-intrepid/.

Here are the steps, I follwed to configure the card in Microsoft Vista

  • Insert card into the laptop and use the “search online” feature for installing the required drivers.
  • Open “Network and Sharing Center”.
  • Click on “Setup up a connection or network”.
  • Choose “Connect to the Internet” option and click on Next.
  • If you are already connected to the Internet, you will get a message stating the same, but choose the “Setup a new connection anyway”.
  • If you already have existing dial-up or DSL connections, choose “No, create a new connection” and click on Next
  • Choose “Dial-up”
  • Choose the modem related to your 3G card.. For example, mine was “Sierra Wireless AirCard 875 HSDPA Modem”
  • Enter the following information in the ISP Information
    • Dial-up phone number : *99#
    • User name : *
    • Password : *
    • Connection Name : Whatever you want to name it

  • Click on Connect and enjoy the broadband speed without bloatware :-) .

HOW TO : Recover deleted SSL certs from IIS

Sunday, November 23rd, 2008

Here’s the situation.. you installed SSL cert on a website in IIS. You think you don’t need that site anymore and delete the site from IIS. The moment you delete it, you bite your tounge and remember that you are supposed to back up the SSL cert for future purposes.. But since the site has been deleted from IIS, you cannot export the key from the IIS manager!!.

Thx to Microsoft’s oversight (or potentially by design), you can still recover the certificate from the server.. Here’s how

  1. Open a MMC console by typing “mmc” in the Start –> Run prompt
  2. In the MMC console, click on File -> Add/Remove Snap-in
  3. In the “Add/Remove Snap-in” window, click on Add
  4. Choose the “certificate” snap-on and click on Add.
  5. Choose Computer Account in the certificate snap-on window and click on Next.
  6. Choose “Local Computer” (Note : If you want to recover from a remote computer, you can put in the UNC path. But you need to have admin rights on that machine) and click on Finish.
  7. Click on close and go back to the MMC console
  8. You will see all the certificates installed on the server
  9. Expand the “personal certificates” folder and you will see the SSL certificate from the website you deleted from IIS. Follow standard steps to export the certificate.