Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Linux list all processes based on memory consumption .

list top 5 processes
ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5

list all processes in assending order .
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS


How to drop cache or in-memory cache on linux and free up some memory ?

$ echo 1 | sudo tee /proc/sys/vm/drop_caches  # drop pagecache
$ echo 2 | sudo tee /proc/sys/vm/drop_caches  # drop dentries and inodes
$ echo 3 | sudo tee /proc/sys/vm/drop_caches  # drop pagecache, dentries and inod

Also we can use 

echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches



This is also used when we take benchmarks of server.

Linux bash script for checking and sending email alerts on disk space issues

#!/bin/sh
FILE=/tmp/mailcontent.txt

> /tmp/mailcontent.txt

df -H | awk '{ print $5 " " $6 }'|head -6|tail -5|while read output;

do
#  echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
echo $usep
  if [ $usep -ge 90 ]; then
   echo -e "Running out of space \n\nPartition:\"$partition ($usep%)\" \nHost:$(hostname) \nDate:$(date)\n" >> /tmp/mailcontent.txt

 fi

done

if [[ -s $FILE ]] ; then

mail -s "CRITICAL ALERT:Disk space of $hostname more that 90%" disk-alert@yourcompany.com
else
echo "$FILE is empty."
fi

exit

Step by step tutorial to configure two node redhat clustering By -- Sojan VM



Two node Red Hat and Clustering
  node1
  node2
  management server
Configure the Shared Storage

Install the clustering software on the nodes
High availability application service “High Availability”
package group  and webserver
service ricci start
provide  passwd for ricci

Install the cluster management software on
the management server
yum groupinstall “High Availability Management”
chkconfig luci on
service luci start












Define a cluster
Node1 and Node2



Then create a partition and format


Define kvm Fence device
Cluster.conf--------------------cluster configuration fine


<?xml version="1.0"?>

<cluster config_version="6" name="cluster">

        <clusternodes>

                <clusternode name="cluster_node1" nodeid="1">

                        <fence>

                                <method name="kvm">

                                        <device domain="cluster_node1" name="kvm"/>

                                </method>

                        </fence>

                </clusternode>

                <clusternode name="cluster_node2" nodeid="2">

                        <fence>

                                <method name="kvm">

                                        <device domain="cluster_node2" name="kvm"/>

                                </method>

                        </fence>

                </clusternode>

        </clusternodes>

        <cman expected_votes="1" two_node="1"/>

        <fencedevices>

                <fencedevice agent="fence_xvm" name="kvm"/>

        </fencedevices>



</cluster>




Kvm Host configuration
Let's start Installing the necessary packages on the host:
yum install   fence-virt fence-virtd fence-virtd-libvirt fence-virtd-multicast
Then create the key needed for the host to authenticate all the fencing requests from the guest cluster:
dd if=/dev/urandom of=/etc/cluster/fence_xvm.key bs=4096 count=1
The key should then be copied to /etc/cluster/fence_xvm.key of every guest.
Now run the configuration tool:
fence_virtd –c
service fence_virtd start
 
check your fence is working or not:
fence_xvm -o reboot –H node2
 
Define Resources For Clustered Web Service
Shared Storage (if not in fstab)
IP address

Apache Resource






Define Failover Domains

Node2































Define Clustered Web Service
Define service
Add storage resource (if not in fstab)
Add ip address resource

add script resource








Basic redhat cluster management commands used in managing mysql cluster




'clustat' ~= Will show the status of the cluster
'clusvcadm -R mysql-svc' ~= Will restart MySQL in place on the same server
'clusvcadm -r mysql-svc -m ' ~= Will relocate MySQL to that node
'clusvcadm -d mysql-svc' ~= Will disable MySQL
'clusvcadm -e mysql-svc' ~= Will enable MySQL

How to get list of all cron jobs ( crontab ) in a server

Run below as root :


for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done


If you want to see who owns that cron job run below :

for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done


getent passwd cut -d: -f1 perl -e'while(<>){chomp;$l = `crontab -u $_ -l 2>/dev/null`;print "$_\n$l\n" if $l}'

Step by Step method to install Media Wiki

Step-By-Step Installation Procedure of Mediawiki on Ubuntu Server 9.04 or Other Distribution as well (If it is rpm distribution replace aptitude/apt-get to yum)

Ubuntu installation using these commands:
aptitude Update
aptitude install apache2 mysql-server php5 php5-mysql mediawiki php5-gd -y

After installation Make sure that Apache is up and running

gedit /etc/apache2/apache2.conf 

(Note that it’s a good idea to back up any system configuration file before editing it. You can do so quickly by using sudo cp /etc/apache2/apache2.conf ~/Desktop to save a copy to your Desktop. You can of course use vi or emacs or the editor of your choice, but most new users seem to prefer gedit’s GUI.)

Once you are in gedit, add the following line to the end of the file:

AddType application/x-httpd-php .html 

Save the file and exit gedit.
Now we’ll need to prepare MySQL for use with MediaWiki. First, you’ll need to run MySQL’s install script:
sudo mysql_install_db
Once this is completed, log into the MySQL command-line client:
mysql -u root –p
Enter your MySQL root user password from above, and you’ll find yourself at the MySQL> local client prompt. First, create a database for MediaWiki to use:
CREATE DATABASE mediawiki;
(Note that all commands entered in the MySQL local client must end with a semicolon to denote the end of the statement.)

Once the database is created, you’ll need to create a database user so MediaWiki can access your newly created database. While still in the MySQL command line client, type this:

CREATE USER mediawikiuser; 

Then create a password for your new user (note that your password will actually go within the quotation marks, and is case-sensitive):

SET PASSWORD FOR mediawikiuser = PASSWORD(“password”); 

Now that you’ve got your MediaWiki database and your MediaWiki database user, you’ll need to grant the user all permissions on the database (again, the password goes within the quotation marks, and is case sensitive):

GRANT ALL PRIVILEGES ON mediawiki.* TO mediawikiuser@localhost IDENTIFIED BY ‘password’; 

(Make sure to append “@localhost” to mediawikiuser; otherwise you might get a database error later on when MediaWiki tries to run its installation script.)
Configure MediaWiki
gedit /etc/mediawiki/apache.conf
Remove the '#' on the third line so that line reads:

Alias /mediawiki /var/lib/mediawiki
/etc/init.d/apache2 restart 
http://localhost/mediawiki ( Follow up the Index page Configuration U need to give the database username and password etc)
Note: makesure user the username, password and Database should be correct

Step by step Method to install OpenNMS

Note: Make sure snmp is already installed on the Server. If not run

apt-get install snmpd -y 

Add the OpenNMS Repository to Your sources.list


deb http://debian.opennms.org stable main
deb-src http://debian.opennms.org stable main 

Add the OpenNMS PGP Key to APT

wget -O - http://debian.opennms.org/OPENNMS-GPG-KEY | sudo apt-key add - 
apt-get update 

(or)

apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 4C4CBBD9
apt-get update
Installing PostgreSQL


apt-get install postgresql-8.3  
Modify pg_hba.conf file in /etc/postgresql/8.3/main/ 
comment all other lines in this file.

local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
# IPv6 local connections:
host    all         all         ::1/128               trust
host    all         all         192.168.1.0           255.255.255.0 trust     <=== Double check 192.168.1.0 it can be 10.10.20.0

Edit postgresql.conf to Allow TCP/IP Connections

vi /etc/postgresql/8.3/main/postgresql.conf 
Uncomment following line 
listen_addresses = 'localhost' 

Restart the Postgresql Database

/etc/init.d/postgresql-8.3 restart 

Installing OpenNMS

apt-get install opennms 
we need to set opennms home in /etc/environment

add the following line
OPENNMS_HOME=/usr/share/opennms 
execute the following command for setting OPENNMS_HOME for existing session 
export OPENNMS_HOME=/usr/share/opennms 
Before you can run the post-install, OpenNMS needs to be configured  to use an appropriate Java Runtime Environment (JRE). The OpenNMS tool  runjava is used to set this up, and it can either search for a suitable  JRE or you can tell it exactly which JRE to use.

# /usr/share/opennms/bin/runjava -s 

This tool will setup the opennms database within PostgreSQL among other things.

# /usr/share/opennms/bin/install -l /usr/local/lib -dis 

you should see similar output after executing above command

- checking table "qrtz_fired_triggers"...
- checking table "qrtz_fired_triggers"... CREATED
- granting access to 'qrtz_fired_triggers' for user 'opennms'... DONE
- checking table "qrtz_scheduler_state"...
- checking table "qrtz_scheduler_state"... CREATED
- granting access to 'qrtz_scheduler_state' for user 'opennms'... DONE
- checking table "qrtz_locks"...
- checking table "qrtz_locks"... CREATED
- granting access to 'qrtz_locks' for user 'opennms'... DONE
- creating tables... DONE
- inserting initial table data for "categories"... OK
- inserting initial table data for "qrtz_locks"... OK
- inserting initial table data for "distPoller"... OK
- checking if iplike is usable... YES
- checking for stale eventtime.so references... OK 
Installer completed successfully! 
Start opennms using the following command

/etc/init.d/opennms start 
OpenNMS will take some time to start, you can check the status of opennms using the following command
root@server1:/usr/local/lib# /etc/init.d/opennms status
OpenNMS.Eventd         : running
OpenNMS.Trapd          : running 
OpenNMS.Queued         : running
OpenNMS.Actiond        : running
OpenNMS.Capsd          : running
OpenNMS.Notifd         : running
OpenNMS.Scriptd        : running
OpenNMS.Rtcd           : running
OpenNMS.Pollerd        : running
OpenNMS.PollerBackEnd  : running
OpenNMS.Ticketer       : running
OpenNMS.Collectd       : running
OpenNMS.Threshd        : running
OpenNMS.Discovery      : running
OpenNMS.Vacuumd        : running
OpenNMS.EventTranslator: running
OpenNMS.PassiveStatusd : running
OpenNMS.Statsd         : running
OpenNMS.Importer       : running
OpenNMS.JettyServer    : running
opennms is running 
if you are able to see like above your opennms is running without any problems.
If you don't see the above output and get at error asking you to look at a log file.. /var/log/opennms/daemon/output.log and the log file mentions the following error..
An error occurred while attempting to start the "OpenNMS:Name=Dhcpd"
service (class org.opennms.netmgt.dhcpd.jmx.Dhcpd).  Shutting down and exiting.
Edit the file $OPENNMS_HOME/etc/service-configuration.xml and comment out the following portion as follows; and restart the opennms service.

<service>
               <name>OpenNMS:Name=Dhcpd</name>
               <class-name>org.opennms.netmgt.dhcpd.jmx.Dhcpd</class-name>
               <invoke at="start" pass="1" method="start"/>
               <invoke at="status" pass="0" method="status"/>
               <invoke at="stop" pass="0" method="stop"/>
</service>

Finally you can access web UI using the following URL ( replace yourhost to the IP of the opennms server)
http://yourhost:8980/opennms
Configuration of OpenNMS
Login in to the web interface  with  login / pass  admin/admin
Configure Discovery - Select  Home  /  Admin  /  Discovery  / Add New    -- Include Range.
Configure SNMP  - Select Home  / Admin  / Configure SNMP by IP

Database Login Details
opennms/postgres ( test user and password i have given )
 
Add Alert sound to the OpenNMS webUI 
In /usr/share/opennms/jetty-webapps/opennms/includes/servicesdown-box.jsp 
Find below tags should be at the end of the file
 
  
<c:otherwise>
  <embed src="tngchime.wav" type="audio/x-pn-realaudio-plugin" hidden="true" autostart="true" loop="false" height="0"  width="0">
  <ul class="plain">
  <c:forEach var="summary" items="${summaries}">
  <c:url var="nodeLink" value="element/node.jsp">
  <c:param name="node" value="${summary.nodeId}"/>
  </c:url>
  <li><a href="${nodeLink}">${summary.nodeLabel}</a> (${summary.fuzzyTimeDown})</li>
  </c:forEach>
  </ul>
  <c:if test="${moreCount > 0}">
  <p class="noBottomMargin" align="right">
  <c:url var="moreLink" value="outage/current.jsp"/>
  <a href="${moreLink}">${moreCount} more...</a>
  </p>
  </c:if>
  </c:otherwise>
The line with the  tag is new, the rest is stock 
Download the following .wav file and pleace it in /usr/share/opennms/jetty-webapps/
wget http://www.nirvani.net/misc/trek_sounds/tngchime.wav

You don't need to restart OpenNMS to effect
Once you are done with above settings please install QuickTimeInstaller.exe in your windows system and restart the browser if opennms find any outages as soon as you login to OpenNMS webGUI you will hear alert sound ( check your sound volume)

Step by step method to create a SSL certificate for your websites

cd  /etc/apache2/ssl/client

Run following commands

openssl genrsa -des3 -out client.key 1024
openssl req -new -key client.key -out client.crs
openssl ca -in client.crs -cert ../ca/ca.crt -keyfile ../ca/ca.key -out client.crt
openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12




Importing Certs in Browser

Make sure to enter the password which was assigned during cert creation.

FireFox

1) Remove your current Certificates.
Firefox : Preferences > Advanced > Encryption > View Certificates > Your Certificates > Select Certificates and Delete.
2) Import : select client.p12 password: test123

Chrome

1) Remove your current Certificates.
   Chrome > Preferences > Under the Hood > Manage Certificates > Remove current one..and import the new one.
2) Import  select 
Import : select client.p12 password: test123
 

How to troubleshoot IP conflicts between Servers / Systems

when we have ip conflicts between two Systems/Servers and you dont know what server ping is responding. Just give below command it requires nmap to be installed

nmap -sV -O -v ipaddress

From the below i found that the response is coming from Server1.demo.com and more to it we
can also see what operating system it is running and what are the open ports of that server.

root@naresh:/home/cp# nmap -sV -O -v 192.168.1.12


Starting Nmap 5.00 ( http://nmap.org ) at 2011-11-14 15:27 IST
NSE: Loaded 3 scripts for scanning.
Initiating ARP Ping Scan at 15:27
Scanning 192.168.1.12 [1 port]

Completed ARP Ping Scan at 15:27, 0.02s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 15:27
Completed Parallel DNS resolution of 1 host. at 15:27, 0.03s elapsed
Initiating SYN Stealth Scan at 15:27
Scanning 192.168.1.12 [1000 ports]
Discovered open port 3306/tcp on 192.168.1.12
Discovered open port 111/tcp on 192.168.1.12
Discovered open port 80/tcp on 192.168.1.12
Discovered open port 25/tcp on 192.168.1.12
Discovered open port 8080/tcp on 192.168.1.12
Discovered open port 53/tcp on 192.168.1.12
Discovered open port 443/tcp on 192.168.1.12
Discovered open port 8009/tcp on 192.168.1.12
Discovered open port 2049/tcp on 192.168.1.12

Completed SYN Stealth Scan at 15:27, 0.04s elapsed (1000 total ports)
Initiating Service scan at 15:27
Scanning 9 services on 192.168.1.12

Completed Service scan at 15:28, 46.06s elapsed (9 services on 1 host)
Initiating OS detection (try #1) against 192.168.1.12
NSE: Script scanning 192.168.1.12.
NSE: Script Scanning completed.
Host 192.168.1.12 is up (0.000088s latency).
Interesting ports on 192.168.1.12:

Not shown: 991 closed ports
PORT     STATE SERVICE    VERSION
25/tcp   open  smtp       Postfix smtpd
53/tcp   open  tcpwrapped
80/tcp   open  http       Apache httpd 2.2.12 ((Ubuntu))
111/tcp  open  rpcbind
443/tcp  open  ssl/http   Apache httpd 2.2.12 ((Ubuntu))
2049/tcp open  rpcbind
3306/tcp open  mysql      MySQL 5.1.37-1ubuntu5.5
8009/tcp open  ajp13?
8080/tcp open  http       Apache Tomcat/Coyote JSP engine 1.1
MAC Address: 00:25:90:62:4B:62 (Super Micro Computer)
Device type: general purpose
Running: Linux 2.6.X
OS details: Linux 2.6.24 - 2.6.28
Uptime guess: 0.113 days (since Mon Nov 14 12:45:28 2011)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=197 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: Host:  Server1.demo.com

Iptables Port forwarding for VNC

 
 /sbin/iptables -A PREROUTING -t nat -p tcp -d $NATIP --dport 5900 -m 
state --state NEW,ESTABLISHED,RELATED -j DNAT --to 192.168.0.2:5900
 

Password less login's between servers ( ssh , scp , rsync)

For a particular user


/home/username/.ssh   ( go to this directory if that directory does not exists create one with name .ssh )

The key generated for password less login is user specific. So create separate keys for each user.


Goto .ssh directory

ssh-keygen -t rsa  (give that command and click next next as usual :) )


It will generate id_rsa and id_rsa.pub two files

one is private key and another is public key

now append the contents of id_rsa.pub to file authorized_keys in the system you want to connect

the file authorized_keys will be in .ssh directory of the other system if that file is not there create it.

cat id_rsa.pub >> ~/.ssh/authorized_keys

now try user@192.168.1.2 ( if 192.168.1.2 is the system you want to connect without password)


Hard disk cloning in linux

To Replace the hard disk need to be taken the clone of the new hard disk

The procedure is as follows:

Cloning a hard drive is a good way to create an "image," or snapshot of our current operating system as a back-up. It is also useful if we want to transfer the contents of the running mangement node computer exactly as it is, complete with all preferences, from an old drive to a new one.

Instructions:

--Back up all important data, in case anything goes wrong.

--Detach any storage devices--including external drives, memory cards, cameras and memory cards--besides the drive you want to clone and the destination drive where you want to store the image.

--Boot the computer where vx64 is running with Linux live CD.
--Learn the naming scheme for the computer's drives by opening a Linux terminal window and typing the following command:

#sudo fdisk -l
--Take note of (and preferably write down) the information under the "Device" column. It will include a list of one or more items named /dev/sda1, /dev/sda2, /dev/sdb, and so forth. The letters (sda, sdb) indicate separate hard drives. The numbers (sda1, sda2) indicate separate partitions within each drive.

Note: The new hard disk is raw..hence need to format the raw hard disk by typing the command

#mkfs

hence the fdisk will show the new hard disk as dev/sdb as if the old one is dev/sda.

--Using the information you obtained from the previous step(#fdisk -l), determine which is your source drive (/dev/sda) and your destination drive (dev/sdb).

--Some clues include the size of the respective drives and their partitions. For example: You are trying to clone a 60-gigabyte source drive onto a 120-gigabyte destination drive. If the previous step tells you /dev/sda has a 60-gigabyte capacity and /dev/sdb has a 120-gigabyte capacity, you can use their respective sizes to tell which is which. Another example: You are copying a three-partition source drive onto a blank destination drive. You see four rows labelled: /dev/sda1, /dev/sda2, /dev/sda3 and /dev/sdb. Next to them are numbers that correspond to each of your partitions and a blank field next to /dev/sdb. You can conclude that sda is your source drive and sdb is your destination drive.

--Open a terminal window.
--Type in the following command, replacing SOURCE with the name of the source drive and DESTINATION with the name of your destination drive:

#dd bs=4k if=/dev/sda of=/dev/sdb conv=noerror,sync

--Here, if=... sets the source and of=... sets the destination. "dd" doesn't care of the contents of the hard disk. It just reads bytes from /dev/sda and writes them into /dev/sdb. It doesn't know what are files. So, the hard disk file system and how many partitions it has are not important. For example, if /dev/sda is splitted into three partitions, the /dev/sdb will have the same partitions. i.e. "destination" is completely same with "source"

Note:To clone only one partition from the source drive, specify the partition (e.g., /dev/sda1 or /dev/sda2). To clone the entire drive, specify only the drive name, with no partition number (e.g., /dev/sda).

to execute "dd" you should login as "root" or switch to "root" using "su" command. And you must be careful, a small mistake may cause a serious problem!

--Wait. Cloning a large drive using dd can take hours, and according to some accounts, even more than a day.

Tips & Warnings:

--After the process is complete, test whether cloning took place properly by attempting to boot from your destination drive.

--Giving dd to the wrong source and destination drives can cause you to overwrite important data. Be sure to input the correct source and destination drives. Always back up important data before attempting this process.

Most of time we don't want to make a complete duplication of hard disk. Then we may prefer to creating an image file of the hard disk and save it in other storage devices. The following command will create an image file "disk1.img" in your user's directory from /dev/sda:

#dd if=/dev/sda of=~/disk1.img

Since you have created an image file, you can compress it with "gzip" or "bzip2":

gzip disk1.img #generates disk1.img.gz or

bzip2 disk1.img #generates disk1.img.bz2

You can save much storage space with compression. But it will take very long time.

To restore a partition or a hard disk from an image file, just exchange the arguments "if" and "of". For example, restore the whole hard disk from the image file "disk1.img":
#dd if=disk1.img of=/dev/sda

Restore the first partition of /dev/sda from the image file "disk2.img":

dd if=disk2.img of=/dev/sda1


My practical test in our lab environment

-Created on virtual machine(min10GB) on esxi box

-After success ful installation shutdown the virtual machine and added new hard disk form the vsphere client add and remove console with incresing the disk size upto 12 GB

-now the boot priority changed to cdrom as the first boot device and the vm is booted with the live cd of Ubuntu linux.

-- formated the new hard disk and mounted the volume and cloned the old hard disk to the new one with "ddcommand"
-- after completion of the process the boot priority is chnaged the new harddisk and booted

-- after successful boot the os on the new hard disk is running fine and proper.

Set java path on Ubuntu meachine

open Vi /etc/bash.bashrc


and then append the following lines


export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

How to check hard disk health in linux step by step

First check for I/O errors in /var/log/messages  if you found any error then there is something wrong with hard disk.

There is SMART utility for monitoring hard disks

SMART stands for Self-Monitoring, Analysis, and Reporting Technology

for using this SMART utilities first we should make sure that feature is enabled  in BIOS

 there are some tools that need to be installed for using this feature

to check weather SMART tools are installed and SMART commands work use this command


smartctl -i /dev/sda1 or sda2 etc...

In ubuntu we can install tools by

sudo apt-get install smartmontools
for checking health use

smartctl -a /dev/hda

example output
-------------------------------------------------------------------------------------

smartctl version 5.37 [i686-pc-linux-gnu] Copyright (C) 2002-6 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital Caviar SE family
Device Model:     WDC WD3200JB-00KFA0
Serial Number:    WD-WCAMR2493175
Firmware Version: 08.05J08
User Capacity:    320,072,933,376 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   6
ATA Standard is:  Exact ATA specification draft version not indicated
Local Time is:    Sat Apr 17 12:39:35 2010 CDT
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x84) Offline data collection activity
                                        was suspended by an interrupting command                              from host.
                                        Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.
Total time to complete Offline
data collection:                 (9600) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off supp                             ort.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        No General Purpose Logging support.
Short self-test routine
recommended polling time:        (   2) minutes.
Extended self-test routine
recommended polling time:        ( 116) minutes.
Conveyance self-test routine
recommended polling time:        (   6) minutes.

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_                             FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   200   200   051    Pre-fail  Always       -                                    0
  3 Spin_Up_Time            0x0003   247   188   021    Pre-fail  Always       -                                    2633
  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -                                    949
  5 Reallocated_Sector_Ct   0x0033   186   186   140    Pre-fail  Always       -                                    105
  7 Seek_Error_Rate         0x000f   200   200   051    Pre-fail  Always       -                                    0
  9 Power_On_Hours          0x0032   074   074   000    Old_age   Always       -                                    19124
 10 Spin_Retry_Count        0x0013   100   100   051    Pre-fail  Always       -                                    0
 11 Calibration_Retry_Count 0x0012   100   100   051    Old_age   Always       -                                    0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -                                    876
194 Temperature_Celsius     0x0022   116   103   000    Old_age   Always       -                                    34
196 Reallocated_Event_Count 0x0032   180   180   000    Old_age   Always       -                                    20
197 Current_Pending_Sector  0x0012   200   200   000    Old_age   Always       -                                    0
198 Offline_Uncorrectable   0x0010   200   200   000    Old_age   Offline      -                                    0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -                                    0
200 Multi_Zone_Error_Rate   0x0009   200   200   051    Pre-fail  Offline      -                                    0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
No self-tests have been logged.  [To run self-tests, use: smartctl -t]


SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

--------------------------------------------------------------------------------------------------------------------------------

smartctl -d ata -a /dev/sda
or
smartctl -d ata -H /dev/sdb


smartctl -t long /dev/sda

example output
-----------------
smartctl version 5.37 [i686-pc-linux-gnu] Copyright (C) 2002-6 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Execute SMART Extended self-test routine immediately in off-line mode".
Drive command "Execute SMART Extended self-test routine immediately in off-line mode" successful.
Testing has begun.
Please wait 116 minutes for test to complete.
Test will complete after Sat Apr 17 14:49:23 2010


Once the test is completed we can see the output by

sudo smartctl -d ata --attributes --log=selftest /dev/sda