Saturday, May 1, 2010

Monitoring SMART hdd data in linux

When I was using Windows, I used to manually monitor S.M.A.R.T. status of my hard disk drive, say, once a month with Everest utility program. Is there such a tool for GNU/Linux? The smartmontools package provides smartd SMART disk monitoring daemon and smartctl SMART disks control and monitor utility.

The command

# smartctl -i /dev/sda

prints the following information (-i) on my HDD (/dev/sda):

smartctl 5.39 2009-08-08 r2872~ [x86_64-unknown-linux-gnu] (openSUSE RPM)
Copyright (C) 2002-9 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF INFORMATION SECTION ===
Model Family: Hitachi Travelstar 5K160 series
Device Model: HITACHI xxx######x#xx##
Serial Number: xx#x##x#xx#xxx
Firmware Version: SBDIC7JP
User Capacity: 120,034,123,776 bytes
Device is: In smartctl database [for details use: -P show]
ATA Version is: 7
ATA Standard is: ATA/ATAPI-7 T13 1532D revision 1
Local Time is: Sat May 1 23:01:43 2010 MSD
SMART support is: Available - device has SMART capability.
SMART support is: Enabled


And the command

# smartctl -A /dev/sda

list all the familiar SMART attributes (-A) and their values:

smartctl 5.39 2009-08-08 r2872~ [x86_64-unknown-linux-gnu] (openSUSE RPM)
Copyright (C) 2002-9 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF READ SMART DATA SECTION ===
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 0x000b 100 100 062 Pre-fail Always - 0
2 Throughput_Performance 0x0005 100 100 040 Pre-fail Offline - 4564
3 Spin_Up_Time 0x0007 253 253 033 Pre-fail Always - 0
4 Start_Stop_Count 0x0012 099 099 000 Old_age Always - 3007
5 Reallocated_Sector_Ct 0x0033 100 100 005 Pre-fail Always - 0
7 Seek_Error_Rate 0x000b 100 100 067 Pre-fail Always - 0
8 Seek_Time_Performance 0x0005 100 100 040 Pre-fail Offline - 0
9 Power_On_Hours 0x0012 081 081 000 Old_age Always - 8418
10 Spin_Retry_Count 0x0013 100 100 060 Pre-fail Always - 0
12 Power_Cycle_Count 0x0032 099 099 000 Old_age Always - 2653
191 G-Sense_Error_Rate 0x000a 100 100 000 Old_age Always - 0
192 Power-Off_Retract_Count 0x0032 100 100 000 Old_age Always - 73465872
193 Load_Cycle_Count 0x0012 089 089 000 Old_age Always - 118737
194 Temperature_Celsius 0x0002 148 148 000 Old_age Always - 37 (Lifetime Min/Max 14/45)
196 Reallocated_Event_Count 0x0032 100 100 000 Old_age Always - 0
197 Current_Pending_Sector 0x0022 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0008 100 100 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x000a 200 253 000 Old_age Always - 0
223 Load_Retry_Count 0x000a 100 100 000 Old_age Always - 0


Please note, that all mentioned commands are executed in superuser mode.

By the way, manual page on -A (--attributes) key provides comprehensive information on interpretation of SMART attributes for newbies.

Computations in linux command line

The bc command is useful to perform some simple arithemetical calculations in console. It may be used in scripts too.

For example, percent values from my previous post have been obtained as

$> echo '265594/292891' | bc -l
$> echo '262938/292891' | bc -l

Argument of echo contains an arithmetic express, and echo pipes it to the bc with standard math library attached (-l).

Do you want to know the Euler's number e (the base of the natural logarithm)?

$> echo 'e(1)' | bc -l

Let's print first 80 digits of π (pi) using arctangent function (a(1.0)):

$> echo 'scale=80; 4.0*a(1.0)' | bc -l

The bc has interactive mode as well; just type

$> bc

In order to quit from interactive mode, type quit or exit.

Optimizing PNG with optipng and pngcrush

There several tools to perform lossless optimization of images in PNG format.
My favourite GNU/Linux distro repositories contain two ones: optipng and pngcrush.

Pngcrush is invoked as follows:

$> pngcrush -e .opt.png -brute *.png

The command tries to reduce size of all PNG files from current directory (*.png) using brute-force search (-brute). Of course, you may omit the -brute key and use default heuristics (which is much faster and produce comparable compression). Resulting files will have .opt.png suffix (-e .opt.png), i.e. vpn-nm-7.png becomes vpn-nm-7.opt.png.

In order to get more information on pngcrush command line keys type:

$> pngcrush -h | less

Another program, optipng, is a bit more friendly, for my taste.
Its syntax is quite similar:

$> optipng -keep -o7 *.png

The command optimizes all PNG images from current directory (*.png) using exhastive search (-o7) and keeps backups (-keep).

As usual, in order to get more information on optipng type:

$> man optipng 

Finally, I have written down compression ratios of pngcrush and optipng on my eight small test PNG files obtained from KSnapshot.

pngcrush - 265594/292891 bytes - 90.7%
optipng  - 262938/292891 bytes - 89.8%

Query recently installed packages in openSUSE

The following command prints the list of recently installed packages in openSUSE GNU/Linux:
$> rpm -qa --last
I believe it should work in other RPM-base distros as well. Alternative title for this entry could be the following: list installed rpm-packages by date.