Wednesday, March 14, 2012

Is your ssh login slow? It could be DNS issue

There could be  various reasons that could result in slow ssh login. Usually it's DNS configuration issue on your server.

In my SUSE environment,
#ping www.google.com
would wait 15 seconds before it displayed something like this
PING www.l.google.com (74.125.227.19) 56(84) bytes of data

I had similar 15 seconds delay for ssh login. Thus, I used following option in  sshd_config file (located under /etc/ssh/sshd_config)
UseDNS  no

Restart SSH Daemon
#service sshd restart

Now there is no delay in SSH login.

However delay in pining google.com was still bothering me. Finally I figured out that you shouldn't be changing DNS configuration from /etc/resolv.conf if you are using netconfig or YaST tool. Thus to clean this mess, I ran following commmand

#netconfig update -f

This command updated  resolv.conf as per netconfig/YaST configuration for DNS and my pinging issue was resolved.
I know you might be thinking of enabling UseDNS for ssh. Yes, you can do it as DNS issue is resolved.

Good Luck



Tuesday, March 6, 2012

WordFinder script: The script that crawls thru' every files to find what you are looking for

Have you ever wanted to find the 'word' in files located under directory containing sub-directories and tons of files. It would be nightmare to search in individual file. You can make your life easy by writing a script that crawls thru' every files under that directory and return the file name along with the line that contains the word you are looking for.

Ok let's get started with BASH script that will do the job for us.

$vim WordFinder.sh
#!/bin/bash
#Author: erdevendra@gmail.com
#
#Usage: This scripts finds a word in each and every files located under the specified location

#
#Syntax:
# .\WordFinder.sh
#

for x in `find $1 -type f`
do
#find files under the specified location and use for loop to go thru each files
         grep -i $2 $x
#search for the pattern in the file
          if [ $? -eq 0 ]
#Check if grep cmd executed successfully
             then echo $x
#if grep cmd executed successfully (i.e if pattern found) display the file name
          fi
#end IF loop
done
#end FOR loop


Give an executable permission to the file

#chmod 777 WordFinder.sh

(Note: 777 gives full permission to everyone in the system)

You are good to go. Now you just need to run that script to find what you are looking for.

Example:
#WordFinder.sh  <location>  <word_you_are_looking_for>

Let's say I want to find word 'listen' in '/etc' directory, I can run following command:
#WordFinder.sh  /etc  listen