Showing posts from October, 2009

Using find command in Linux/Unix

find is one of the unix power tools that searches for files within a directory hiererchy . It is a delight for Sys Admin and provides lots of options to refine our search.

Using find command :

Simple executing find in the current directory will give  a full listing of all files in the current directory and all subdirectories including hidden files:


The syntax of find is as follows

find   [path...]   [expression]

path:            the directory under which search is performed
expression:  expression is made of options , tests based on which find will perform its search operation. We can also perform some action based on the results of our search

Some of the useful options are:

-name:      To find based on file name
-perm:      To find based on file permission . We can also add [+|-] sign with -perm mode to refine our    search more . If the perm option is preceded by a `-(minus)` sign, then it searches for files wherein  atleast  all of the bits in the mode are set in the file's mo…

How to check whether a CPU is 64 bit or 32 bit in Unix

Determine whether a CPU has 64 bit capability or not .

We know about uname command . Using it ,we can get similiar information, but that information is for the running version of the kernel . We need to know the 64 bit capability of the CPU  . This can be determined by either reading the /proc/cpuinfo file or by using the dmidecode command. Let's see how we can use those commands .

Using /proc/cpuinfo

This virtual file gives information regarding the processors in computer . Among the information it provides are CPU vendor , speed and No of CPUs and many flags giving various features of the CPU.  Let's consider the following output of /proc/cpuinfo taken from my host.

zaman@personal-desk ~]$ cat /proc/cpuinfo 
processor: 0
vendor_id: GenuineIntel
cpu family: 6
model: 7
model name: Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz
stepping: 6
cpu MHz: 2992.520
cache size: 6144 KB
physical id: 0
siblings: 2
core id: 0
cpu cores: 2
fdiv_bug: no
hlt_bug: no
f00f_bug: no
coma_bug: no
fpu: yes

Using lsof to identify deleted files:


Today's post is on another interesting problem which we had seen last week on our production servers . These servers are mainly responsible for reading data from some group of server hosts and transfers the same data to another batch of hosts. We are receiving disk space alerts for /home partition getting filled up for some of these servers.On checking these hosts ,we can see that df is reporting more than 90% utilisation for /home.We considered using du to identify which files and directories are consuming the space. And we are surprised with the results of du. du is only reporting around 40% disk utilisation for /home. So , is df is lying or du is lying . We will see in the next section , how we tracked the issue and was able to identify where the rest of disk space has gone.
The following are the disk usage results.

$ df -h /home/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/sys-home 137G 117G 14G 90% /home
$ sudo du -sh /home/

Using Dmidecode : Getting BIOS information and other hardware information

Using Dmidecode

How to get the BIOS information . Earlier , myself and probably many people used to go BIOS to get the BIOS version and retrieving information regarding hardware :). What if the machine is a production host . We cannot shutdown the host to get the BIOS information . In such type of a situation, the dmidecode tool comes handy. It is a command line tool and can be freely used as it is released under General Public Licence (GPL).

About Dmidecode:

Dmidecode will report  information regarding your system's hardware as described in the system's BIOS . It will give information like your BIOS version, BIOS vendor , CPU information , System Board information and other hardware information. Please note that we cannot always reliably believe in the results of dmidecode as dmidecode does not scan your hardware and simply collects the information from the BIOS.

Using Dmidecode:

Like various other unix tools , dmidecode is also a command-line utility.It has few…

Using ipmitool: rc.shutdown: 30 second watchdog timeout expired. Shutdown terminated.


In this post , we will try to diagnose a production host which frequently goes to unresponsive/hung state . The host needs to be rebooted to get it back online. No information can be found in system logs regarding the sudden unresponsiveness, no trace of hacker attack can be seen. Hardware looks to be fine also. Finally, came across the ipmitool utility and Phew!, after so much of investigation, we finally were able to identify the root cause for this behaviour .

About IMPItool:

IPMItool is a command line utility for managing and configuring devices that supports  Intelligent Platform Management Interface (IPMI) . IPMI is an open standard for monitoring, logging, recovery, inventory, and control of hardware that is implemented independent of the main CPU, BIOS, and OS. The service processor (or Baseboard Management Controller, BMC) is the brain behind platform management and its primary purpose is to handle the autonomous sensor monitoring and event logging features.


Passphrase-less Authentication and using ssh-agent


Passphraseless Authentication is logging onto a remote system without supplying the passphrase or password.The disadvantage with password authentication is that if transmitted in plaintext, then there is  a possibility that is can  sniffed by someone over the network and read it since it is in plaintext , can be logged by keystroke logger , can be seen over the shoulders as you type and also susceptible to brute-force attacks . OpenSSH allows public key authentication as an alternative to password authentication.Public key Authentication uses a key-pair for authentication. The private key is stored securely on the local host while the public key is copied to the remote SSH server.We can use these keys for passphraseless authentication  either by using
1)  ssh-agent or
2)  protecting the private key with a blank password which is not recommened

Key Generation:

ssh-keygen is a utility that can be used to generate authentication keys. It can be used to create RSA keys for us…

Changing Layout of partition in Linux


There was a requirement of porting some native applications running on FreeBSD Unix to Linux. These applications are written using C language and they  are using /home/app as their root directory. That means we are having   directories like /home/app/bin , /home/tmp , /home/app/sbin , /home/app/var etc on these FreeBSD hosts . These hosts were not running any well known internet services or any OS related application but running only our custom native applications.

Issues and Solutions:

These applications when ported to Linux are failing because of the layout of /tmp directory in Linux . /tmp was created as  a separate partition in our Linux hosts and our requirement was that we need a /tmp directory under /home partition for applications to run properly.  For directories under /home/app , we created the necessary directories based on similar layout of FreeBSD.
We decided to change the layout of /tmp directory of Linux without modifying the code.
The following are the conc…

Configuring an FTP server using vsFTPD

FTP:The Basics:

FTP is the Internet standard File Transfer Protocol that is used to send and receive files over the Internet . It runs over TCP and uses two separate ports for control and data connections between the client and server applications . Control port uses Port 21 which is used for sending control information such as username , password, put/get commands, etc while data files are usually transferred on port 20.

Modes of Running FTP

 FTP runs in two modes : Active and Passive

Active FTP: In active mode , the FTP server initiates a data transfer connection back to the client . This is the flow.

1. FTP client connects from a random unprivileged port (N > 1023) to the FTP server's control port , port 21.
2. The client then starts listening on port N+1 and sends the FTP command PORT N+1 to the  FTP server.
3. The server will then connect back to the client's specified data port from its local data port , which is port 20.

Passive FTP:
In passive mode , the FT…