Pages

Unixbhaskar's Blog

Monday, September 13, 2010

LDAP: The tool to manage enterprise infrastructure

I am provoked or compelled or whatever you say to write this article about this topic and the article that spurs the interest is here and many more on the internet by some brilliant guys and that's reminds me of dealing with LDAP with one of my job assignment.Without doubt I must say it is a complex topic to deal with( at least my bend of mind says so.. YMMV).But having said that it is an absolute must for any administrator handling large network infrastructure in the corporation should be very well aware of this protocol as well the usability of it.

I do not issue any guarantee that this will work for you.

I am assuming that readers are aware of this protocol, if not then please look in OpenLDAP Website to get an idea of it.OpenLDAP is an open source suite of software that includes the LDAP server daemon (slapd), a replication daemon (slurpd) and a small collection of command line client tools, like ldapsearch and ldapadd, among others. In this article, we'll set up and populate a small but functional LDAP server using the slapd daemon, and start to make use of it with a Linux client.


Definition and Components

LDAP stands for Lightweight Directory Access Protocol, which is to say that, by definition, LDAP is a protocol, and nothing else. However, the protocol exists to perform operations on data, and is really pretty useless without it. This brings up the components that make up an LDAP deployment: client software used to send LDAP requests, the server daemon that handles incoming LDAP requests, and the back-end data store. I will refer to the last two collectively as a "directory service."

Back-end Data Storage

Of these components, the back-end data storage mechanism is the least relevant to you unless you're administering a production LDAP deployment. Developers writing code that accesses an LDAP server and end users who access a directory service via some client utility should be happy to let the protocol do the job of getting data to them without knowing anything about the back end. Adding, removing, updating, deleting, and fetching data from a directory service occurs through the LDAP protocol.

Now there are few variant of the LDAP thing like :

a)OpenLDAP

b) FDS(Fedora Directory Server)

c) Novell's eDirectory

d)Sun Java System Directory or formarly iPlanet

So we will sticks with OpenLDAP in this article to investigate with.

What Is LDAP Used For?

An LDAP directory service stores information for use by systems as well as end users (and their various applications). Probably the most common use of LDAP is for replacing either flat-file authentication (think /etc/passwd) or legacy networked authentication (think NIS). The benefit of any networked authentication mechanism over a flat file system is clearly that it lifts the burden of having to keep files on all of your systems in sync. The benefit of LDAP over, say, NIS is (among other things) a finer-grained control over the data and how it is accessed (and by whom). You can also make encrypted connections to LDAP servers using TLS or SSL, and you never have to muck with flat file "maps" or complicated Makefiles to change the data.

Because LDAP is a transaction-based system, operations that complete successfully are immediately "live." Modern Unix-based systems (including Linux, BSD, and OS X) can rely on LDAP to get just about any information they could store in flat files or NIS, including hosts, automounter configuration, users, groups, and more. Add to that the ability to have Samba, Apache, PAM, tcpwrappers, Sendmail, and other applications talk to LDAP for authentication, aliases, and other tidbits of useful information, and you have the beginnings of a very well-integrated, easily maintained, authoritative data source for your entire infrastructure.

LDAP is also popular for use as a "white pages" directory for a department or corporation. For example, most email applications, from Mutt and Pine to Outlook, Evolution, and KMail all know how to talk to an LDAP server. This makes it very easy to, for example, tell KMail to autocomplete addresses as you type using an LDAP directory as its addressbook source instead of (or in addition to) local files.To add to the list Thunderbird too will support that protocol.

A Closer Look at LDAP Data

It's extremely important when learning about LDAP and how it deals with data to separate the structure (or topology) of the data from the definitions of the objects themselves.

Simply, the structure of LDAP data is a hierarchical collection of objects. Objects can represent anything from people to printers and take their places within the hierarchy using whatever logic you like.

Objects?

Yes, objects. Each object has a list of attributes associated with it that describe that particular object. When you add or delete an object, make a request for an object, or change the value of an object's attribute, you do so solely using the LDAP protocol. In short, LDAP exists to manipulate or fetch data about objects.

Hierarchical?

The layout of the data in an LDAP directory is the Directory Information Tree (DIT). You can customize it to the needs of your organization, but it's still a hierarchical tree structure. This tree is not dissimilar to a typical filesystem; there's a "top" or "root" directory, under which are high-level objects (directories in a filesystem). Those help you to categorize the lower level objects that you're really interested in (in a filesystem, these are the files themselves).

Suppose you want to store information about people using a hierarchical collection of objects. Viewing things as a filesystem, you could create a /People directory, and under that, create a file--/People/whatEverYouWant. That file contains attribute name and value pairs to describe "steve." One attribute might be "firstname," with a value of "Dan." Save the file, and create a new one for each person. Eventually, you have a filesystem that looks something like:

/people
Steve
Dan
Bhaskar

We might create it like department wise like this:

/people
/Engineering
Bhaskar
Dan
Jones
/Finance
Marry
Garth

LDAP data are represented in the LDIF(LDAP Data Interchange Format).

What Are Objectclasses?

Objectclasses are prototypes for entries that will actually exist in your directory server. The objectclass definition (which uses ASN.1 syntax) specifies which attributes may or must be used by LDAP entries declared as instances of a particular objectclass.

Get it? Let me explain it backward, in the way that most people get into LDAP: you want to store information about people. The most common attributes associated with people are:

* First name
* Last name
* Email address
* Phone numbers
* Room numbers

These attributes are great for setting up an office whitepages server that users can refer to for information about people in their office. The key now is finding out which objectclass definitions either require or allow for the use of these attributes. When I started with LDAP, I researched this by perusing the actual schema files that come with most (if not all) directory servers. These files are human-readable.

Object Class Definitions

Here's the definition of the inetOrgPerson objectclass, which is a good place to start:

objectclass ( 2.16.840.1.113730.3.2.2
NAME 'inetOrgPerson'
DESC 'RFC2798: Internet Organizational Person'
SUP organizationalPerson
STRUCTURAL
MAY (
audio $ businessCategory $ carLicense $ departmentNumber $
displayName $ employeeNumber $ employeeType $ givenName $
homePhone $ homePostalAddress $ initials $ jpegPhoto $
labeledURI $ mail $ manager $ mobile $ o $ pager $
photo $ roomNumber $ secretary $ uid $ userCertificate $
x500uniqueIdentifier $ preferredLanguage $
userSMIMECertificate $ userPKCS12 )



The first line states that what follows is an objectclass definition, as opposed to an attributetype definition. The long number is the ASN.1 number assigned to the objectclass. If you create your own objectclasses, this number is significant; it's where you use your organization's IANA Enterprise Number to identify any objectclasses that you create.

The NAME line should be self explanatory. It is the name that will appear in your users' entries to state that the user is of type inetOrgPerson. This line gives you license to use any of the attributes in the objectclass definition to describe the user.

The DESC line is usually a useful description that can help you use this object in a way appropriate to the intent of the definer. You don't want to use objectclasses in a completely unorthodox way, because when you reach out to others for help, they'll find themselves asking you more questions than you ask them, which is often a sign that you've gone off in the wrong direction.

The SUP line is critical, and the theory is tough to describe without getting pretty verbose. SUP is short for SUPERIOR, and it names another objectclass from which this objectclass inherits. In this case, the superior or parent objectclass is organizationalPerson. The organizationalPerson class inherits from the person objectclass, which inherits from an objectclass called top. If an objectclass has no other superiors, it is always a child of the top objectclass.

It's an inheritance chain. You need to understand it, because some LDAP servers strictly enforce it, and if you violate it in the creation of your entries, the directory server will unceremoniously spit them back at you.

The MAY line is actually a block. That block (between parentheses) contains a list, delimited with the $ symbol, of all of the attributes that MAY be used to describe an object declared of the type inetOrgPerson.

OK enough internals..lets go ahead and install and deploy the thing.For more curious reader I will provide you the link from where this article is influenced in resource section in the end.

Installing OpenLDAP:

You can download OpenLDAP from the OpenLDAP website. While it is certainly possible to obtain precompiled binary distributions of OpenLDAP in RPM, deb, and other package formats, these tend to be somewhat older releases. There are many useful customizations you can make during an OpenLDAP compile, and I've never had much trouble compiling OpenLDAP from source, so this is the method I'm advocating.

This is not to say that there are absolutely no dependencies to satisfy. There are two major dependencies, both of which are very easy to handle:

Berkeley DB

The OpenLDAP team strongly recommends using Sleepycat Software's Berkeley DB as the data storage mechanism for an OpenLDAP deployment. As we mentioned in Part One of the series, LDAP is not a database, but a protocol for accessing and managing data. But the data has to live somewhere, and Berkeley DB is easy to deal with, even for newbie admins. If you're among those who have nightmares about databases, take heart in knowing that OpenLDAP does a superb job at hiding the fact that you're even dealing with one. Download the Berkeley DB source from the user-friendly Sleepycat download page. For my test build, I used Berkeley DB 4.1.25 without strong encryption support.

Building Berkeley DB couldn't be easier. Unpack the tarball, cd to the build_unix directory, and type ../dist/configure, followed by make and make install (the last as root). This will create a directory called /usr/local/BerkeleyDB.4.1, which contains all of the pertinent parts we need for our OpenLDAP installation.

OpenSSL for LDAPS

If you're using Redhat, Fedora,Gentoo,Arch,Debian or any number of other recent distributions, OpenSSL is probably already installed. If it isn't, and you wish to enable secure connections to your LDAP server, you need to install it. Luckily, this is a breeze. Grab a source tarball from the OpenSSL Download Page. Untar it, cd to the resulting directory, and run the standard configure and make commands. I also recommend that you run make test, and then (as root, of course) make install. This puts everything you need in the /usr/local/ssl directory by default.


Anyway I have created a user and group which will be able to operate the ldap thing going.Here is that:

bhaskar@bhaskar-laptop_14:51:17_Mon Sep 13:~> id ldap
uid=439(ldap) gid=439(ldap) groups=439(ldap)


Now we need to investigate the slapd.conf file,this is the file which drive ldap.So here we go:

Here's a quick and dirty slapd.conf that gets the daemon up and running and allows an administrative user to manipulate data:

include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema


Schema files define objects and attributes. When the slapd daemon starts, it includes whichever schema files we tell it to here, and that determines the types of objects and attributes supported by that slapd daemon. So, for example, if we did not include the nis.schema file, we would not be able to add typical Unix accounts using only the other schema files we've included. Schema files are human-readable, and you could even create your own schema files if you needed some wacky object-types that aren't already defined.

allow bind_v2
pidfile /var/run/slapd.pid


In newer versions of OpenLDAP, only LDAPv3 binds are allowed by default, which has caused many a mailing list crisis, since there are applications that don't support making a version 3 bind to a directory server. In the event we come across any in our travels, we've allowed LDAPv2 binds for our proof-of-concept, as you can see here:

database bdb
suffix "dc=bhaskar-laptop,dc=localdomain"
rootdn "cn=Manager,dc=bhaskar-laptop,dc=localdomain"
rootpw secret ------------> which is generated by slappasswd previously,just cut and paste
directory /var/lib/ldap

Our database backend is the Berkeley database, which OpenLDAP knows as "bdb." The slapd.conf man page can tell you other possible values for the database directive. Our suffix uses what's known as the "domain component" model. This model just takes the parts of a domain and references each part of the domain name as a separate domain component (dc). We'll talk more about this in a future article.

The rootdn and rootpw values define the administrative username and password for performing on the directory or its data operations that require administrative priveleges. The username is defined using a common name (cn), and the object entry for that user is stored directly under our top-level entry -- hence the trailing domain components. The password is generated using the slappasswd command, which simply prompts you for a password and generates output which can be cut and pasted into the slapd.conf file, as I've done here.

directory tells the slapd daemon where to store the data files for this particular database definition. There can be several database sections in a slapd.conf file. Here, we're telling slapd to use its home directory as its data storage directory, which is why the ldap user must be able to write there.

index objectClass eq,pres
index ou,cn,mail,surname,givenname eq,pres,sub
index uidNumber,gidNumber,loginShell eq,pres
index uid,memberUid eq,pres,sub


Defining indexes at this early stage won't make a great amount of difference. However, as the directory grows and more demands are placed upon it, indexes can mean the difference between users who don't notice that things that used to be handle by, say, NIS are now handled by something else, and a completely unusable directory server.

Now all boil down to starting the ldap daemon that slapd like below:

/etc/init.d/slapd start------------------> Every others else

or

/etc/rc.d/slapd start ------------> Gentoo ,Arch and variant

or

service slapd start ------------> Fedora and Redhat variant


Still it depend on the OS you sit on..but the intention would be same..

Resources:

a)LDAP

b)LDAP-data

c)OpenLDAP Install

d)OpenLDAP Install -II

e)OpenLdap Administration

Hope this will help.

Cheers!
Bhaskar

Thursday, September 2, 2010

Important system tools- part-II

This is a second article related to this(system tools) information .You can find the first part here . Ok GNU/Linux come with so many wonderful tools that one entire book will not suffice to write about it.As it visible everywhere.

I do not issue any guarantee that this will work for you.

I am going to take you through some tricky tools GNU/Linux provide to deal with oddity or complexity.Important to understand administrators love these kind tools under thier armory to shoot out problem as precisely as possible ,so they can concentrate on other equally important matters at hand.Time management is one of the key to become a efficent administrator at production environment.

So here we go.

Dmidecode:

A bit of explanation about it first. This tool will reveal the BIOS information of the system .So it's a handy way to know about it without rebooting the system.Most of the distros these days have it in thier respective repositories.

bhaskar@bhaskar-laptop_05:29:31_Thu Sep 02:~> sudo /usr/sbin/dmidecode
# dmidecode 2.10
SMBIOS 2.4 present.
25 structures occupying 1236 bytes.
Table at 0x000F25D2.

Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
Vendor: Hewlett-Packard
Version: 68MSU Ver. F.03
Release Date: 08/15/2007
Address: 0xE0000
Runtime Size: 128 kB
ROM Size: 1024 kB
Characteristics:
PCI is supported
PC Card (PCMCIA) is supported
PNP is supported
BIOS is upgradeable
BIOS shadowing is allowed
Boot from CD is supported
Selectable boot is supported
EDD is supported
3.5"/720 kB floppy services are supported (int 13h)
Print screen service is supported (int 5h)
8042 keyboard services are supported (int 9h)
Serial services are supported (int 14h)
Printer services are supported (int 17h)
ACPI is supported
USB legacy is supported
LS-120 boot is supported
Smart battery is supported
BIOS boot specification is supported
Function key-initiated network boot is supported
Targeted content distribution is supported
BIOS Revision: 15.3
Firmware Revision: 132.14

Handle 0x0001, DMI type 1, 27 bytes
System Information
Manufacturer: Hewlett-Packard
Product Name: Compaq Presario B1200
Version: F.03
Serial Number: CNU8011ZJZ
UUID: 24FEFA40-3A15-E011-3F84-6D9910097D29
Wake-up Type: Power Switch
SKU Number: GP279PA#ACJ
Family: 103C_5335KV

Handle 0x0040, DMI type 126, 42 bytes
Inactive

Handle 0x0002, DMI type 2, 8 bytes
Base Board Information
Manufacturer: Hewlett-Packard
Product Name: 0AC0
Version: KBC Version 84.0E
Serial Number: Not Specified

Handle 0x0003, DMI type 3, 13 bytes
Chassis Information
Manufacturer: Hewlett-Packard
Type: Notebook
Lock: Not Present
Version: Not Specified
Serial Number: CNU8011ZJZ
Asset Tag: CNU8011ZJZ
Boot-up State: Safe
Power Supply State: Safe
Thermal State: Safe
Security Status: External Interface Enabled

Handle 0x0041, DMI type 126, 32 bytes
Inactive

Handle 0x0004, DMI type 4, 35 bytes
Processor Information
Socket Designation: U10
Type: Central Processor
Family: Pentium M
Manufacturer: Intel(R)
ID: FD 06 00 00 FF FB EB BF
Signature: Type 0, Family 6, Model 15, Stepping 13
Flags:
FPU (Floating-point unit on-chip)
VME (Virtual mode extension)
DE (Debugging extension)
PSE (Page size extension)
TSC (Time stamp counter)
MSR (Model specific registers)
PAE (Physical address extension)
MCE (Machine check exception)
CX8 (CMPXCHG8 instruction supported)
APIC (On-chip APIC hardware supported)
SEP (Fast system call)
MTRR (Memory type range registers)
PGE (Page global enable)
MCA (Machine check architecture)
CMOV (Conditional move instruction supported)
PAT (Page attribute table)
PSE-36 (36-bit page size extension)
CLFSH (CLFLUSH instruction supported)
DS (Debug store)
ACPI (ACPI supported)
MMX (MMX technology supported)
FXSR (Fast floating-point save and restore)
SSE (Streaming SIMD extensions)
SSE2 (Streaming SIMD extensions 2)
SS (Self-snoop)
HTT (Hyper-threading technology)
TM (Thermal monitor supported)
PBE (Pending break enabled)
Version: Intel(R) Core(TM)2 Duo CPU T5450 @ 1.66GHz
Voltage: 1.1 V
External Clock: 166 MHz
Max Speed: 1667 MHz
Current Speed: 1667 MHz
Status: Populated, Enabled
Upgrade: None
L1 Cache Handle: 0x0005
L2 Cache Handle: 0x0006
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified

Handle 0x0005, DMI type 7, 19 bytes
Cache Information
Socket Designation: Internal L1 Cache
Configuration: Enabled, Not Socketed, Level 1
Operational Mode: Write Back
Location: Internal
Installed Size: 64 kB
Maximum Size: 64 kB
Supported SRAM Types:
Burst
Installed SRAM Type: Burst
Speed: Unknown
Error Correction Type: Unknown
System Type: Unified
Associativity: 4-way Set-associative

Handle 0x0006, DMI type 7, 19 bytes
Cache Information
Socket Designation: Internal L2 Cache
Configuration: Enabled, Not Socketed, Level 2
Operational Mode: Write Back
Location: External
Installed Size: 2048 kB
Maximum Size: 2048 kB
Supported SRAM Types:
Burst
Installed SRAM Type: Burst
Speed: Unknown
Error Correction Type: None
System Type: Unified
Associativity: 4-way Set-associative

Handle 0x0007, DMI type 9, 13 bytes
System Slot Information
Designation: PC CARD-Slot 0
Type: 32-bit PC Card (PCMCIA)
Current Usage: Available
Length: Short
ID: Adapter 0, Socket 0
Characteristics:
5.0 V is provided
3.3 V is provided
PC Card-16 is supported
Cardbus is supported
PME signal is supported

Handle 0x0008, DMI type 10, 6 bytes
On Board Device Information
Type: Video
Status: Enabled
Description: 8

Handle 0x0009, DMI type 11, 5 bytes
OEM Strings
String 1: www.hp.com
String 2: ABS 70/71 79 7A 7B 7C

Handle 0x000A, DMI type 16, 15 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 4 GB
Error Information Handle: No Error
Number Of Devices: 2

Handle 0x000B, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x000A
Error Information Handle: No Error
Total Width: 64 bits
Data Width: 64 bits
Size: 512 MB
Form Factor: SODIMM
Set: None
Locator: DIMM #1
Bank Locator: Not Specified
Type: DDR2
Type Detail: Synchronous
Speed: 667 MHz
Manufacturer: Hyundai Electronics
Serial Number: 0000403D
Asset Tag: Not Specified
Part Number: HYMP564S64CP6-Y5

Handle 0x000C, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x000A
Error Information Handle: No Error
Total Width: 64 bits
Data Width: 64 bits
Size: 512 MB
Form Factor: SODIMM
Set: None
Locator: DIMM #2
Bank Locator: Not Specified
Type: DDR2
Type Detail: Synchronous
Speed: 667 MHz
Manufacturer: Hyundai Electronics
Serial Number: 0000403A
Asset Tag: Not Specified
Part Number: HYMP564S64CP6-Y5

Handle 0x000D, DMI type 19, 15 bytes
Memory Array Mapped Address
Starting Address: 0x00000000000
Ending Address: 0x0003FFFFFFF
Range Size: 1 GB
Physical Array Handle: 0x000A
Partition Width: 0

Handle 0x000E, DMI type 20, 19 bytes
Memory Device Mapped Address
Starting Address: 0x00000000000
Ending Address: 0x0001FFFFFFF
Range Size: 512 MB
Physical Device Handle: 0x000B
Memory Array Mapped Address Handle: 0x000D
Partition Row Position: 1

Handle 0x000F, DMI type 20, 19 bytes
Memory Device Mapped Address
Starting Address: 0x00020000000
Ending Address: 0x0003FFFFFFF
Range Size: 512 MB
Physical Device Handle: 0x000C
Memory Array Mapped Address Handle: 0x000D
Partition Row Position: 2

Handle 0x0010, DMI type 22, 26 bytes
Portable Battery
Location: Primary
Manufacturer: Hewlett-Packard
Manufacture Date: 11/13/2007
Serial Number: 27074
Name: HP
Chemistry: Lithium Ion
Design Capacity: 25500 mWh
Design Voltage: 14400 mV
SBDS Version: Not Specified
Maximum Error: Unknown
OEM-specific Information: 0x00000000

Handle 0x0011, DMI type 126, 26 bytes
Inactive

Handle 0x0012, DMI type 32, 11 bytes
System Boot Information
Status: No errors detected

Handle 0x0085, DMI type 133, 34 bytes
OEM-specific Type
Header and Data:
85 22 85 00 01 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00
00 00

Strings:

No battery

Handle 0x0086, DMI type 134, 34 bytes
OEM-specific Type
Header and Data:
86 22 86 00 01 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00
00 00
Strings:



Handle 0x0013, DMI type 144, 26 bytes
OEM-specific Type
Header and Data:
90 1A 13 00 FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF 00 00

Handle 0x0014, DMI type 127, 4 bytes
End Of Table



As you can see it will prodeuce hell lot of information.

Ethtool:

This tools to masure and know information about the attached ethernet card.Like the previous one this tool is also available with most of distributions repository.

bhaskar@bhaskar-laptop_05:37:54_Thu Sep 02:~> sudo /usr/sbin/ethtool -i eth0
driver: tg3
version: 3.108
firmware-version: sb v2.09
bus-info: 0000:18:00.0

bhaskar@bhaskar-laptop_05:38:06_Thu Sep 02:~> sudo /usr/sbin/ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Advertised auto-negotiation: Yes
Speed: Unknown! (65535)
Duplex: Unknown! (255)
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: g
Current message level: 0x000000ff (255)
Link detected: no





Blkid:

This tool is for getting the device id ,which is very unique to help the bootloader think properly.In other word not messed up with bootloader if you put this indentification number of disk instead of directly mention them like this /dev/sdX.

bhaskar@bhaskar-laptop_05:48:57_Thu Sep 02:~> sudo /sbin/blkid
Password:
/dev/sda1: UUID="f6f903f1-03cd-4387-933c-8c928514c958" TYPE="ext3" SEC_TYPE="ext2"
/dev/sda2: UUID="a9380f41-173f-41be-8e20-b14fb78eaf9a" TYPE="swap"
/dev/sda3: UUID="3cccbf0e-0354-43b4-b89a-ceee1fcadb31" TYPE="ext3" SEC_TYPE="ext2"
/dev/sda5: LABEL="/" UUID="a217eb70-52b1-4e20-8841-7cb366a54c40" TYPE="ext3"
/dev/sda6: UUID="73917641-fbaf-4910-bf2a-5d86d93fb1ca" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda7: LABEL="Fedora-12-i686-L" UUID="0ba812ef-d38e-4fb6-9a2d-79fcb13768aa" TYPE="ext4"
/dev/sda8: UUID="VwXE29-5Um4-zG0d-PCXe-Anz6-k876-CT3v0G" TYPE="LVM2_member"
/dev/mapper/bhaskarlaptop-data: UUID="09ac6747-95b8-4b62-ac0e-5b80adcd13fe" TYPE="ext3"


It has got so many useful flags through which you can get lot out of it. Please see the manpage reagrding this tool and every tool.

UUID:

As you can understand this is an abbreviation and the full form is "Universally Unique Identifier", which if you can see the previous command on this page; that is apprent from the command output of "blkid" right?

Now if you want to generate a new one means new "Universally Unique Identifier", then you have follow this way,basically it can done by two means one by is generated randomly or through "r" flag of uuidgen binary ot by time base with the help of "-t" flag.Ok I will show you both below:

Time Based:
bhaskar@bhaskar-laptop_06:05:51_Thu Sep 02:~> sudo /usr/bin/uuidgen -t
Password:
0fb2cfd4-b62a-11df-b336-001a4b90dadc


Randomized:
bhaskar@bhaskar-laptop_06:06:43_Thu Sep 02:~> sudo /usr/bin/uuidgen -r
Password:
c31645c4-7d72-493b-a85c-adadd61a0e49


Cool!! right.

Socklist:

As you can guess from the name that this command will going to enlist the socket running on the system for that it turn to /proc file system.

bhaskar@bhaskar-laptop_06:30:19_Thu Sep 02:~> sudo /usr/bin/socklist
type port inode uid pid fd name
tcp 111 7001 0 3010 8 rpcbind
tcp 80 6061 0 4077 3 httpd
tcp 53 5985 0 2792 21 named
tcp 53 5983 0 2792 20 named
tcp 25 6329 0 2904 12 master
tcp 953 5993 0 2792 22 named
tcp 17500 14128 1000 3047 18 dropbox
tcp 646 7030 0 3014 3 famd
tcp 80 0 0 0 0
udp 53 5984 0 2792 513 named
udp 53 5982 0 2792 512 named
udp 17500 14124 1000 3047 15 dropbox
udp 111 6995 0 3010 6 rpcbind
udp 123 5934 0 2791 5 ntpd
udp 641 7000 0 3010 7 rpcbind




Udisks:

This tool will show the system bus service with attached devices.It will spit out quite a verbose information.

bhaskar@bhaskar-laptop_06:37:01_Thu Sep 02:~> sudo /usr/bin/udisks --dump
========================================================================
Showing information for /org/freedesktop/UDisks/devices/dm_2d0
native-path: /sys/devices/virtual/block/dm-0
device: 254:0
device-file: /dev/dm-0
presentation: /dev/dm-0
by-id: /dev/disk/by-id/dm-name-bhaskarlaptop-data
by-id: /dev/disk/by-id/dm-uuid-LVM-gQo1BYHBfV6WxRuYfF3PO3YRgD1QSX7HyRhtgrM7prRmAE41YvqJsbtBRAA9wvdt
by-id: /dev/disk/by-uuid/09ac6747-95b8-4b62-ac0e-5b80adcd13fe
detected at: Wed 01 Sep 2010 10:34:56 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:56 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 1
mount paths: /lvm
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 1
presentation name:
presentation icon:
size: 26843545600
block size: 512
job underway: no
usage: filesystem
type: ext3
version: 1.0
uuid: 09ac6747-95b8-4b62-ac0e-5b80adcd13fe
label:
LVM2 Logical Volume:
LV name: data
LV uuid: yRhtgr-M7pr-RmAE-41Yv-qJsb-tBRA-A9wvdt
VG name: bhaskarlaptop
VG uuid: gQo1BY-HBfV-6WxR-uYfF-3PO3-YRgD-1QSX7H

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sda
native-path: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
device: 8:0
device-file: /dev/sda
presentation: /dev/sda
by-id: /dev/disk/by-id/ata-ST9160821AS_5MA8QHLW
by-id: /dev/disk/by-id/scsi-SATA_ST9160821AS_5MA8QHLW
by-path: /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0
detected at: Wed 01 Sep 2010 10:34:55 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:55 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 160041885696
block size: 512
job underway: no
usage:
type:
version:
uuid:
label:
partition table:
scheme: mbr
count: 8
drive:
vendor: ATA
model: ST9160821AS
revision: 3.BHE
serial: 5MA8QHLW
WWN:
detachable: 0
can spindown: 1
rotational media: Yes, unknown rate
write-cache: enabled
ejectable: 0
adapter: /org/freedesktop/UDisks/adapters/0000_3a00_3a1f_2e2
ports:
/org/freedesktop/UDisks/adapters/0000_3a00_3a1f_2e2/host0
similar devices:
media:
compat:
interface: ata
if speed: (unknown)
ATA SMART: Updated at Thu 02 Sep 2010 06:10:21 AM IST
overall assessment: UNKNOWN
===============================================================================
Attribute Current|Worst|Threshold Status Value Type Updates
===============================================================================
raw-read-error-rate 113|100| 6 good 52163879 Pre-fail Online
spin-up-time 99| 99| 0 n/a 0 Old-age Online
start-stop-count 97| 97| 20 good 3771 Pre-fail Online
reallocated-sector-count 100|100| 36 good 0 sectors Pre-fail Online
seek-error-rate 68| 60| 30 good 133359356520 Pre-fail Online
power-on-hours 94| 94| 0 n/a 225.4 days Old-age Online
spin-retry-count 100|100| 34 good 0 Pre-fail Online
power-cycle-count 98| 98| 20 good 2062 Pre-fail Online
attribute-184 100|253| 0 n/a 0 Old-age Online
reported-uncorrect 100|100| 0 n/a 0 sectors Old-age Online
attribute-188 100|100| 45 good 0 Old-age Online
high-fly-writes 90| 90| 0 n/a 10 Old-age Online
airflow-temperature-celsius 52| 36| 0 n/a 48C / 118F Old-age Online
power-off-retract-count 100|100| 0 n/a 213 Old-age Online
load-cycle-count 1| 1| 0 n/a 207899 Old-age Online
temperature-celsius-2 48| 64| 0 n/a 48C / 118F Old-age Online
hardware-ecc-recovered 82| 61| 0 n/a 225063895 Old-age Offline
current-pending-sector 100|100| 0 n/a 0 sectors Old-age Online
offline-uncorrectable 100|100| 0 n/a 0 sectors Old-age Offline
udma-crc-error-count 200|200| 0 n/a 0 Old-age Online
multi-zone-error-rate 100|253| 0 n/a 0 Old-age Offline
ta-increase-count 100|253| 0 n/a 0 Old-age Offline

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sda1
native-path: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
device: 8:1
device-file: /dev/sda1
presentation: /dev/sda1
by-id: /dev/disk/by-id/ata-ST9160821AS_5MA8QHLW-part1
by-id: /dev/disk/by-id/scsi-SATA_ST9160821AS_5MA8QHLW-part1
by-id: /dev/disk/by-uuid/f6f903f1-03cd-4387-933c-8c928514c958
by-path: /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part1
detected at: Wed 01 Sep 2010 10:34:56 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:56 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 50001444864
block size: 512
job underway: no
usage: filesystem
type: ext3
version: 1.0
uuid: f6f903f1-03cd-4387-933c-8c928514c958
label:
partition:
part of: /org/freedesktop/UDisks/devices/sda
scheme: mbr
number: 1
type: 0x83
flags:
offset: 32256
alignment offset: 0
size: 50001444864
label:
uuid:

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sda2
native-path: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda2
device: 8:2
device-file: /dev/sda2
presentation: /dev/sda2
by-id: /dev/disk/by-id/ata-ST9160821AS_5MA8QHLW-part2
by-id: /dev/disk/by-id/scsi-SATA_ST9160821AS_5MA8QHLW-part2
by-id: /dev/disk/by-uuid/a9380f41-173f-41be-8e20-b14fb78eaf9a
by-path: /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part2
detected at: Wed 01 Sep 2010 10:34:56 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:56 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 2303078400
block size: 512
job underway: no
usage: other
type: swap
version: 2
uuid: a9380f41-173f-41be-8e20-b14fb78eaf9a
label:
partition:
part of: /org/freedesktop/UDisks/devices/sda
scheme: mbr
number: 2
type: 0x82
flags:
offset: 50001477120
alignment offset: 0
size: 2303078400
label:
uuid:

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sda3
native-path: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda3
device: 8:3
device-file: /dev/sda3
presentation: /dev/sda3
by-id: /dev/disk/by-id/ata-ST9160821AS_5MA8QHLW-part3
by-id: /dev/disk/by-id/scsi-SATA_ST9160821AS_5MA8QHLW-part3
by-id: /dev/disk/by-uuid/3cccbf0e-0354-43b4-b89a-ceee1fcadb31
by-path: /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part3
detected at: Wed 01 Sep 2010 10:34:56 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:56 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 13999426560
block size: 512
job underway: no
usage: filesystem
type: ext3
version: 1.0
uuid: 3cccbf0e-0354-43b4-b89a-ceee1fcadb31
label:
partition:
part of: /org/freedesktop/UDisks/devices/sda
scheme: mbr
number: 3
type: 0x83
flags:
offset: 52304555520
alignment offset: 0
size: 13999426560
label:
uuid:

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sda4
native-path: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda4
device: 8:4
device-file: /dev/sda4
presentation: /dev/sda4
by-id: /dev/disk/by-id/ata-ST9160821AS_5MA8QHLW-part4
by-id: /dev/disk/by-id/scsi-SATA_ST9160821AS_5MA8QHLW-part4
by-path: /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part4
detected at: Wed 01 Sep 2010 10:34:56 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:56 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 1024
block size: 512
job underway: no
usage:
type:
version:
uuid:
label:
partition:
part of: /org/freedesktop/UDisks/devices/sda
scheme: mbr
number: 4
type: 0x05
flags:
offset: 66303982080
alignment offset: 0
size: 93735290880
label:
uuid:

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sda5
native-path: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5
device: 8:5
device-file: /dev/sda5
presentation: /dev/sda5
by-id: /dev/disk/by-id/ata-ST9160821AS_5MA8QHLW-part5
by-id: /dev/disk/by-id/scsi-SATA_ST9160821AS_5MA8QHLW-part5
by-id: /dev/disk/by-uuid/a217eb70-52b1-4e20-8841-7cb366a54c40
by-path: /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part5
detected at: Wed 01 Sep 2010 10:34:56 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:56 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 1
mount paths: /
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 32901087744
block size: 512
job underway: no
usage: filesystem
type: ext3
version: 1.0
uuid: a217eb70-52b1-4e20-8841-7cb366a54c40
label:
partition:
part of: /org/freedesktop/UDisks/devices/sda
scheme: mbr
number: 5
type: 0x83
flags:
offset: 127138185216
alignment offset: 0
size: 32901087744
label:
uuid:

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sda6
native-path: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6
device: 8:6
device-file: /dev/sda6
presentation: /dev/sda6
by-id: /dev/disk/by-id/ata-ST9160821AS_5MA8QHLW-part6
by-id: /dev/disk/by-id/scsi-SATA_ST9160821AS_5MA8QHLW-part6
by-id: /dev/disk/by-uuid/73917641-fbaf-4910-bf2a-5d86d93fb1ca
by-path: /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part6
detected at: Wed 01 Sep 2010 10:34:56 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:56 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 534610944
block size: 512
job underway: no
usage: filesystem
type: ext3
version: 1.0
uuid: 73917641-fbaf-4910-bf2a-5d86d93fb1ca
label:
partition:
part of: /org/freedesktop/UDisks/devices/sda
scheme: mbr
number: 6
type: 0x83
flags: boot
offset: 66304014336
alignment offset: 0
size: 534610944
label:
uuid:

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sda7
native-path: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7
device: 8:7
device-file: /dev/sda7
presentation: /dev/sda7
by-id: /dev/disk/by-id/ata-ST9160821AS_5MA8QHLW-part7
by-id: /dev/disk/by-id/scsi-SATA_ST9160821AS_5MA8QHLW-part7
by-id: /dev/disk/by-uuid/0ba812ef-d38e-4fb6-9a2d-79fcb13768aa
by-path: /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part7
detected at: Wed 01 Sep 2010 10:34:56 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:56 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 10742183424
block size: 512
job underway: no
usage: filesystem
type: ext4
version: 1.0
uuid: 0ba812ef-d38e-4fb6-9a2d-79fcb13768aa
label: Fedora-12-i686-L
partition:
part of: /org/freedesktop/UDisks/devices/sda
scheme: mbr
number: 7
type: 0x83
flags:
offset: 66838657536
alignment offset: 0
size: 10742183424
label:
uuid:

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sda8
native-path: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8
device: 8:8
device-file: /dev/sda8
presentation: /dev/sda8
by-id: /dev/disk/by-id/ata-ST9160821AS_5MA8QHLW-part8
by-id: /dev/disk/by-id/scsi-SATA_ST9160821AS_5MA8QHLW-part8
by-path: /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part8
detected at: Wed 01 Sep 2010 10:34:56 PM IST
system internal: 1
removable: 0
has media: 1 (detected at Wed 01 Sep 2010 10:34:56 PM IST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 49557279744
block size: 512
job underway: no
usage: raid
type: LVM2_member
version: LVM2\x20001
uuid: VwXE29-5Um4-zG0d-PCXe-Anz6-k876-CT3v0G
label:
partition:
part of: /org/freedesktop/UDisks/devices/sda
scheme: mbr
number: 8
type: 0x8e
flags:
offset: 77580873216
alignment offset: 0
size: 49557279744
label:
uuid:

========================================================================
Showing information for /org/freedesktop/UDisks/devices/sr0
native-path: /sys/devices/pci0000:00/0000:00:1f.1/host3/target3:0:0/3:0:0:0/block/sr0
device: 11:0
device-file: /dev/sr0
presentation: /dev/sr0
by-path: /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:0:0
detected at: Wed 01 Sep 2010 10:34:55 PM IST
system internal: 0
removable: 1
has media: 0
detects change: 1
detection by polling: 1
detection inhibitable: 1
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 0
block size: 0
job underway: no
usage:
type:
version:
uuid:
label:
drive:
vendor: Optiarc
model: DVD RW AD-7560A
revision: DH10
serial:
WWN:
detachable: 0
can spindown: 0
rotational media: Yes, unknown rate
write-cache: unknown
ejectable: 1
adapter: /org/freedesktop/UDisks/adapters/0000_3a00_3a1f_2e1
ports:
/org/freedesktop/UDisks/adapters/0000_3a00_3a1f_2e1/host3
similar devices:
media:
compat: optical_cd optical_cd_r optical_cd_rw optical_dvd optical_dvd_plus_r optical_dvd_plus_r_dl optical_dvd_plus_rw optical_dvd_r optical_dvd_ram optical_dvd_rw optical_mrw optical_mrw_w
interface: scsi
if speed: (unknown)
ATA SMART: not available

========================================================================


I have choose to spit out evrythig with the "--dump" option. You can select lot many thing individually by going through the man page of it.

IPCALC:

This tool will aid you to reveal the base internals of an ip address.It helps an network administrator to figure out the subnet/ip range/netmask very easily by one single command.So how it look like ? Here is the output of the command look :

root@bhaskar-laptop_06:45:35_Thu Sep 2:/ # ipcalc 127.0.0.1
Address: 127.0.0.1 01111111.00000000.00000000. 00000001
Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000
Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111
=>
Network: 127.0.0.0/24 01111111.00000000.00000000. 00000000
HostMin: 127.0.0.1 01111111.00000000.00000000. 00000001
HostMax: 127.0.0.254 01111111.00000000.00000000. 11111110
Broadcast: 127.0.0.255 01111111.00000000.00000000. 11111111
Hosts/Net: 254 Class A, Loopback


You can put any ip-address as an argument.

Ok enough..not to bloat your mind with more information. May be some other related post of mine might reveal bunch of useful tool to navigate through the GNU/Linux system. I have ignored "lsof","lslk","fuser"and many more,because I found that those informations are easily available.

Cheers!
Bhaskar

Tuesday, August 31, 2010

Measuring and monitoring system performances through sysstat

Being an administrator of a corporation to manage production box is an daunting task.One has to be very much aware what is going on into the box/servers by looking into it through some tools.One important package I am talking about is called "sysstats" ,which has so many important tool to disclose all the information needed by an administrator.

I do not issue any guarantee that this will work for you.

So this article I am using Arch Linux . As it doesn't come with base installation so I have to get it(sysstat) separately.

bhaskar@bhaskar-laptop_07:05:26_Tue Aug 31:~> sudo pacman -S sysstat
warning: sysstat-9.0.6.1-1 is up to date -- reinstalling
resolving dependencies...
looking for inter-conflicts...

Targets (1): sysstat-9.0.6.1-1

Total Download Size: 0.00 MB
Total Installed Size: 1.14 MB

Proceed with installation? [Y/n]


here I said N or no ,because I have already installed it long time back.You see that below:

bhaskar@bhaskar-laptop_07:08:31_Tue Aug 31:~> sudo pacman -Qi sysstat
Name : sysstat
Version : 9.0.6.1-1
URL : http://pagesperso-orange.fr/sebastien.godard/
Licenses : GPL
Groups : None
Provides : None
Depends On : glibc
Optional Deps : tk: to use isag
gnuplot: to use isag
Required By : None
Conflicts With : None
Replaces : None
Installed Size : 1168.00 K
Packager : Sergej Pupykin
Architecture : i686
Build Date : Mon 01 Mar 2010 03:51:14 AM IST
Install Date : Tue 02 Mar 2010 10:10:31 PM IST
Install Reason : Explicitly installed
Install Script : No
Description : A collection of performance monitoring tools



Here are the files installed by the package in the system..

bhaskar@bhaskar-laptop_07:10:35_Tue Aug 31:~> sudo pacman -Ql sysstat
sysstat /etc/
sysstat /etc/cron.daily/
sysstat /etc/cron.daily/sysstat
sysstat /etc/cron.hourly/
sysstat /etc/cron.hourly/sysstat
sysstat /etc/rc.d/
sysstat /etc/rc.d/sysstat
sysstat /etc/sysconfig/
sysstat /etc/sysconfig/sysstat
sysstat /etc/sysconfig/sysstat.ioconf
sysstat /etc/sysstat/
sysstat /etc/sysstat/sysstat
sysstat /usr/
sysstat /usr/bin/
sysstat /usr/bin/iostat
sysstat /usr/bin/isag
sysstat /usr/bin/mpstat
sysstat /usr/bin/pidstat
sysstat /usr/bin/sadf
sysstat /usr/bin/sar
sysstat /usr/lib/
sysstat /usr/lib/sa/
sysstat /usr/lib/sa/sa1
sysstat /usr/lib/sa/sa2
sysstat /usr/lib/sa/sadc
sysstat /usr/share/
sysstat /usr/share/doc/
sysstat /usr/share/doc/sysstat-9.0.6.1/
sysstat /usr/share/doc/sysstat-9.0.6.1/CHANGES
sysstat /usr/share/doc/sysstat-9.0.6.1/COPYING
sysstat /usr/share/doc/sysstat-9.0.6.1/CREDITS
sysstat /usr/share/doc/sysstat-9.0.6.1/FAQ
sysstat /usr/share/doc/sysstat-9.0.6.1/README
sysstat /usr/share/doc/sysstat-9.0.6.1/sysstat-9.0.6.1.lsm
sysstat /usr/share/locale/
sysstat /usr/share/locale/af/
sysstat /usr/share/locale/af/LC_MESSAGES/
sysstat /usr/share/locale/af/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/da/
sysstat /usr/share/locale/da/LC_MESSAGES/
sysstat /usr/share/locale/da/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/de/
sysstat /usr/share/locale/de/LC_MESSAGES/
sysstat /usr/share/locale/de/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/es/
sysstat /usr/share/locale/es/LC_MESSAGES/
sysstat /usr/share/locale/es/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/fi/
sysstat /usr/share/locale/fi/LC_MESSAGES/
sysstat /usr/share/locale/fi/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/fr/
sysstat /usr/share/locale/fr/LC_MESSAGES/
sysstat /usr/share/locale/fr/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/id/
sysstat /usr/share/locale/id/LC_MESSAGES/
sysstat /usr/share/locale/id/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/it/
sysstat /usr/share/locale/it/LC_MESSAGES/
sysstat /usr/share/locale/it/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/ja/
sysstat /usr/share/locale/ja/LC_MESSAGES/
sysstat /usr/share/locale/ja/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/ky/
sysstat /usr/share/locale/ky/LC_MESSAGES/
sysstat /usr/share/locale/ky/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/lv/
sysstat /usr/share/locale/lv/LC_MESSAGES/
sysstat /usr/share/locale/lv/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/mt/
sysstat /usr/share/locale/mt/LC_MESSAGES/
sysstat /usr/share/locale/mt/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/nb/
sysstat /usr/share/locale/nb/LC_MESSAGES/
sysstat /usr/share/locale/nb/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/nl/
sysstat /usr/share/locale/nl/LC_MESSAGES/
sysstat /usr/share/locale/nl/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/nn/
sysstat /usr/share/locale/nn/LC_MESSAGES/
sysstat /usr/share/locale/nn/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/pl/
sysstat /usr/share/locale/pl/LC_MESSAGES/
sysstat /usr/share/locale/pl/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/pt/
sysstat /usr/share/locale/pt/LC_MESSAGES/
sysstat /usr/share/locale/pt/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/pt_BR/
sysstat /usr/share/locale/pt_BR/LC_MESSAGES/
sysstat /usr/share/locale/pt_BR/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/ro/
sysstat /usr/share/locale/ro/LC_MESSAGES/
sysstat /usr/share/locale/ro/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/ru/
sysstat /usr/share/locale/ru/LC_MESSAGES/
sysstat /usr/share/locale/ru/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/sk/
sysstat /usr/share/locale/sk/LC_MESSAGES/
sysstat /usr/share/locale/sk/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/sv/
sysstat /usr/share/locale/sv/LC_MESSAGES/
sysstat /usr/share/locale/sv/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/vi/
sysstat /usr/share/locale/vi/LC_MESSAGES/
sysstat /usr/share/locale/vi/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/zh_CN/
sysstat /usr/share/locale/zh_CN/LC_MESSAGES/
sysstat /usr/share/locale/zh_CN/LC_MESSAGES/sysstat.mo
sysstat /usr/share/locale/zh_TW/
sysstat /usr/share/locale/zh_TW/LC_MESSAGES/
sysstat /usr/share/locale/zh_TW/LC_MESSAGES/sysstat.mo
sysstat /usr/share/man/
sysstat /usr/share/man/man1/
sysstat /usr/share/man/man1/iostat.1.gz
sysstat /usr/share/man/man1/isag.1.gz
sysstat /usr/share/man/man1/mpstat.1.gz
sysstat /usr/share/man/man1/pidstat.1.gz
sysstat /usr/share/man/man1/sadf.1.gz
sysstat /usr/share/man/man1/sar.1.gz
sysstat /usr/share/man/man8/
sysstat /usr/share/man/man8/sa1.8.gz
sysstat /usr/share/man/man8/sa2.8.gz
sysstat /usr/share/man/man8/sadc.8.gz
sysstat /var/
sysstat /var/log/
sysstat /var/log/sa/


Now it puts a crontab entry to run daily on the installed system..although you can control it according your choice..

bhaskar@bhaskar-laptop_07:13:35_Tue Aug 31:/etc/cron.daily> cat sysstat
#!/bin/sh
# Generate a daily summary of process accounting. Since this will probably
# get kicked off in the morning, it would probably be better to run against
# the previous days data.
/usr/lib/sa/sa2 -A &


This package come with so many binary and all of them are very useful tool. I will explain all of them one by one.First tool is callled sar..and it will output like this..

bhaskar@bhaskar-laptop_07:15:59_Tue Aug 31:~> sudo sar
Password:
Linux 2.6.34-ARCH (bhaskar-laptop) 08/31/2010 _i686_ (2 CPU)

06:27:36 AM LINUX RESTART

06:28:02 AM CPU %user %nice %system %iowait %steal %idle
06:38:02 AM all 8.57 0.00 1.80 6.59 0.00 83.04
06:48:02 AM all 22.57 0.00 5.11 5.40 0.00 66.92
06:58:02 AM all 16.56 0.00 5.58 3.81 0.00 74.05
07:08:02 AM all 7.46 0.00 2.79 4.52 0.00 85.23
Average: all 13.79 0.00 3.82 5.08 0.00 77.31


Now bit of explanation is required for the fields it shows which I enumerated below:

Sar is system activity reporter.

%user and %nice refer to your software programs, such as MySQL or Apache.
%system refers to the kernel̢۪s internal workings.
%iowait is time spent waiting for Input/Output, such as a disk read or write. Finally, since the kernel accounts for 100% of the runnable time it can schedule, any unused time goes into %idle.

It come along with another two binary relates sar is called sa1 and sa2.What does this fellows do to sar??

The sa1 script logs sar output into sysstat's binary log file format, and sa2 reports it back in human readable format.Clear!

And the reports it provide kept in a dir called /var/log/sa and file with date attached to it...

bhaskar@bhaskar-laptop_07:25:28_Tue Aug 31:/var/log/sa> ls
sa23 sa24 sa25 sa30 sa31 sar24 sar30


"-W" this flag to sar shows the swap related activity on the system

bhaskar@bhaskar-laptop_07:31:09_Tue Aug 31:~> sudo sar -W
Password:
Linux 2.6.34-ARCH (bhaskar-laptop) 08/31/2010 _i686_ (2 CPU)

06:27:36 AM LINUX RESTART

06:28:02 AM pswpin/s pswpout/s
06:38:02 AM 0.00 0.00
06:48:02 AM 0.00 0.00
06:58:02 AM 0.03 1.67
07:08:02 AM 0.01 3.20
07:18:02 AM 0.13 4.02
07:28:01 AM 0.12 0.36
Average: 0.05 1.54



"-r" option to sar show memory related thig from the system:

bhaskar@bhaskar-laptop_07:37:50_Tue Aug 31:~> sudo sar -r
Linux 2.6.34-ARCH (bhaskar-laptop) 08/31/2010 _i686_ (2 CPU)

06:27:36 AM LINUX RESTART

06:28:02 AM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit
06:38:02 AM 204468 815896 79.96 31784 399596 1412880 43.21
06:48:02 AM 62120 958244 93.91 61984 407388 1566932 47.93
06:58:02 AM 40344 980020 96.05 93368 348428 1622948 49.64
07:08:02 AM 27240 993124 97.33 126952 312652 1576108 48.21
07:18:02 AM 72528 947836 92.89 96988 334604 1454800 44.50
07:28:01 AM 58732 961632 94.24 95268 344540 1486996 45.48
Average: 77572 942792 92.40 84391 357868 1520111 46.49


"-b" option shows some paging statistics :

bhaskar@bhaskar-laptop_07:41:19_Tue Aug 31:~> sudo sar -b
Linux 2.6.34-ARCH (bhaskar-laptop) 08/31/2010 _i686_ (2 CPU)

06:27:36 AM LINUX RESTART

06:28:02 AM tps rtps wtps bread/s bwrtn/s
06:38:02 AM 25.49 19.80 5.69 951.22 108.95
06:48:02 AM 35.10 20.35 14.76 259.20 337.45
06:58:02 AM 24.73 16.87 7.86 159.71 230.64
07:08:02 AM 53.55 42.64 10.91 356.85 273.27
07:18:02 AM 61.84 53.96 7.88 477.19 293.56
07:28:01 AM 5.12 1.15 3.96 49.08 74.69
07:38:01 AM 5.75 2.34 3.41 90.68 61.61
Average: 30.23 22.45 7.78 334.87 197.18



Anyway you can fuse your terminal reports into the excel sheet to manage thing as the origianl page is shown the way how to do it.Kndly visit the origianl pacakge author page to see the options.

Ok now lets talk about another binary come with package called "pidstat" What it does??

pidstat command is used to monitor processes and threads currently being managed by the Linux kernel. It can also monitor the children of those processes and threads.

on my system it shows the thing going underneath:

bhaskar@bhaskar-laptop_07:41:22_Tue Aug 31:~> sudo pidstat -d 2
Password:
Linux 2.6.34-ARCH (bhaskar-laptop) 08/31/2010 _i686_ (2 CPU)

07:46:56 AM PID kB_rd/s kB_wr/s kB_ccwr/s Command
07:46:58 AM 990 0.00 11.82 0.00 kjournald
07:46:58 AM 3948 0.00 1.97 1.97 plugin-containe

07:46:58 AM PID kB_rd/s kB_wr/s kB_ccwr/s Command

07:47:00 AM PID kB_rd/s kB_wr/s kB_ccwr/s Command
07:47:02 AM 990 0.00 6.00 0.00 kjournald
07:47:02 AM 3948 0.00 2.00 2.00 plugin-containe

07:47:02 AM PID kB_rd/s kB_wr/s kB_ccwr/s Command
07:47:04 AM 3835 0.00 2.00 2.00 firefox

07:47:04 AM PID kB_rd/s kB_wr/s kB_ccwr/s Command

07:47:06 AM PID kB_rd/s kB_wr/s kB_ccwr/s Command
07:47:08 AM 990 0.00 8.00 0.00 kjournald
07:47:08 AM 3948 0.00 2.00 2.00 plugin-containe

07:47:08 AM PID kB_rd/s kB_wr/s kB_ccwr/s Command

07:47:10 AM PID kB_rd/s kB_wr/s kB_ccwr/s Command
07:47:12 AM 990 0.00 12.00 0.00 kjournald
07:47:12 AM 3948 0.00 2.00 2.00 plugin-containe






"-d" option provide I/O statistics.

Now get the memory utilisation stat through "-r" flag of this binary.

bhaskar@bhaskar-laptop_07:50:18_Tue Aug 31:~> sudo pidstat -r
Linux 2.6.34-ARCH (bhaskar-laptop) 08/31/2010 _i686_ (2 CPU)

07:51:41 AM PID minflt/s majflt/s VSZ RSS %MEM Command
07:51:41 AM 1 0.45 0.00 1752 620 0.06 init
07:51:41 AM 1023 0.54 0.00 2148 948 0.09 udevd
07:51:41 AM 2772 0.02 0.00 5080 428 0.04 syslog-ng
07:51:41 AM 2773 0.09 0.00 5396 1620 0.16 syslog-ng
07:51:41 AM 2804 0.03 0.00 3420 700 0.07 ntpd
07:51:41 AM 2805 0.25 0.00 8232 3848 0.38 named
07:51:41 AM 2824 0.04 0.00 2372 760 0.07 xinetd
07:51:41 AM 2834 0.23 0.00 18672 8492 0.83 httpd
07:51:41 AM 2874 0.05 0.00 18724 6760 0.66 httpd
07:51:41 AM 2875 0.15 0.00 18688 7660 0.75 httpd
07:51:41 AM 2876 0.15 0.00 18688 7660 0.75 httpd
07:51:41 AM 2877 0.14 0.00 18824 7844 0.77 httpd
07:51:41 AM 2878 0.15 0.00 18688 7660 0.75 httpd
07:51:41 AM 2879 0.15 0.00 18688 7660 0.75 httpd
07:51:41 AM 2917 0.13 0.00 8468 1888 0.19 master
07:51:41 AM 2931 0.12 0.00 8540 1760 0.17 pickup
07:51:41 AM 2932 0.12 0.00 8592 1776 0.17 qmgr
07:51:41 AM 2936 0.04 0.00 1800 628 0.06 crond
07:51:41 AM 2946 0.16 0.00 2788 1216 0.12 dbus-daemon
07:51:41 AM 2954 0.60 0.00 15052 3608 0.35 hald
07:51:41 AM 2955 0.19 0.00 3516 1172 0.11 hald-runner
07:51:41 AM 2984 0.08 0.00 3580 992 0.10 hald-addon-inpu
07:51:41 AM 2986 0.08 0.00 3580 988 0.10 hald-addon-rfki
07:51:41 AM 2987 0.08 0.00 3580 984 0.10 hald-addon-leds
07:51:41 AM 2996 0.07 0.00 3576 992 0.10 hald-addon-gene
07:51:41 AM 2998 0.08 0.00 3580 1000 0.10 hald-addon-stor
07:51:41 AM 3008 0.08 0.00 3244 1012 0.10 hald-addon-acpi
07:51:41 AM 3023 0.03 0.00 6216 688 0.07 rpcbind
07:51:41 AM 3027 0.02 0.00 3148 308 0.03 famd
07:51:41 AM 3036 0.02 0.00 1960 356 0.03 gpm
07:51:41 AM 3044 0.24 0.00 13912 2152 0.21 gdm-binary
07:51:41 AM 3060 3.17 0.04 143100 19616 1.92 dropbox
07:51:41 AM 3072 0.04 0.00 1752 536 0.05 agetty
07:51:41 AM 3073 0.04 0.00 1752 540 0.05 agetty
07:51:41 AM 3074 0.04 0.00 1752 540 0.05 agetty
07:51:41 AM 3075 0.04 0.00 1752 536 0.05 agetty
07:51:41 AM 3076 0.04 0.00 1752 532 0.05 agetty
07:51:41 AM 3077 0.04 0.00 1752 536 0.05 agetty
07:51:41 AM 3132 0.25 0.00 17028 2804 0.27 gdm-simple-slav
07:51:41 AM 3155 162.21 0.01 82076 35784 3.51 Xorg
07:51:41 AM 3194 0.28 0.00 18224 2236 0.22 console-kit-dae
07:51:41 AM 3195 0.03 0.00 3528 644 0.06 ntpd
07:51:41 AM 3272 0.03 0.00 3172 332 0.03 dbus-launch
07:51:41 AM 3277 0.24 0.00 5448 2540 0.25 upowerd
07:51:41 AM 3331 0.42 0.00 17664 5400 0.53 polkit-gnome-au
07:51:41 AM 3335 0.25 0.00 5640 2672 0.26 polkitd
07:51:41 AM 3336 0.16 0.00 14888 2064 0.20 gdm-session-wor
07:51:41 AM 3349 0.11 0.00 22176 1432 0.14 gnome-keyring-d
07:51:41 AM 3367 0.73 0.00 25064 5380 0.53 gnome-session
07:51:41 AM 3385 0.03 0.00 3172 332 0.03 dbus-launch
07:51:41 AM 3386 0.09 0.00 2616 1116 0.11 dbus-daemon
07:51:41 AM 3388 0.02 0.00 3540 224 0.02 ssh-agent
07:51:41 AM 3391 0.18 0.00 6776 2580 0.25 gconfd-2
07:51:41 AM 3396 0.69 0.01 22052 7000 0.69 gnome-settings-
07:51:41 AM 3401 0.13 0.00 6352 1708 0.17 gvfsd
07:51:41 AM 3404 0.79 0.00 55332 12088 1.18 metacity
07:51:41 AM 3405 0.90 0.01 42768 11040 1.08 gnome-panel
07:51:41 AM 3407 0.21 0.00 7932 2764 0.27 gvfs-gdu-volume
07:51:41 AM 3409 0.25 0.00 13512 2556 0.25 udisks-daemon
07:51:41 AM 3410 0.03 0.00 5000 512 0.05 udisks-daemon
07:51:41 AM 3425 0.11 0.00 38324 1492 0.15 gvfs-fuse-daemo
07:51:41 AM 3429 1.24 0.02 53156 8800 0.86 nautilus
07:51:41 AM 3431 0.25 0.00 41896 2352 0.23 bonobo-activati
07:51:41 AM 3442 27.99 0.00 20928 6888 0.68 multiload-apple
07:51:41 AM 3445 0.44 0.01 21036 7000 0.69 battstat-applet
07:51:41 AM 3446 0.67 0.00 50716 11744 1.15 gweather-applet
07:51:41 AM 3448 0.74 0.01 41420 11764 1.15 clock-applet
07:51:41 AM 3450 0.70 0.00 41736 11532 1.13 wnck-applet
07:51:41 AM 3451 0.42 0.00 20500 6644 0.65 notification-ar
07:51:41 AM 3452 0.29 0.00 16120 4172 0.41 polkit-gnome-au
07:51:41 AM 3454 0.35 0.00 17840 5308 0.52 gdu-notificatio
07:51:41 AM 3480 0.08 0.00 17236 1460 0.14 gnome-screensav
07:51:41 AM 3502 0.17 0.00 6856 2396 0.23 gvfsd-trash
07:51:41 AM 3509 0.18 0.00 4828 1888 0.19 system-tools-ba
07:51:41 AM 3516 0.13 0.00 6484 1740 0.17 gvfsd-burn
07:51:41 AM 3522 0.76 0.00 12724 10152 0.99 SystemToolsBack
07:51:41 AM 3528 0.76 0.01 47896 12500 1.23 gnome-terminal
07:51:41 AM 3529 0.05 0.00 1796 580 0.06 gnome-pty-helpe
07:51:41 AM 3531 0.15 0.00 4924 1884 0.18 bash
07:51:41 AM 3538 0.07 0.00 4412 844 0.08 screen
07:51:41 AM 3539 0.13 0.00 4676 1372 0.13 screen
07:51:41 AM 3540 0.16 0.00 4924 1892 0.19 bash
07:51:41 AM 3546 0.14 0.00 4000 900 0.09 su
07:51:41 AM 3547 0.20 0.00 4900 1876 0.18 bash
07:51:41 AM 3577 0.04 0.00 2144 844 0.08 udevd
07:51:41 AM 3578 0.03 0.00 2144 864 0.08 udevd
07:51:41 AM 3611 0.16 0.00 4924 1872 0.18 bash
07:51:41 AM 3617 0.26 0.01 4884 1796 0.18 bash
07:51:41 AM 3628 0.16 0.00 4924 1876 0.18 bash
07:51:41 AM 3635 0.21 0.01 5136 1164 0.11 bash
07:51:41 AM 3655 0.21 0.00 4924 1920 0.19 bash
07:51:41 AM 3674 0.14 0.00 4000 904 0.09 su
07:51:41 AM 3675 0.16 0.00 4900 1868 0.18 bash
07:51:41 AM 3684 0.27 0.01 5552 2740 0.27 bash
07:51:41 AM 3701 1.87 0.00 4924 1956 0.19 bash
07:51:41 AM 3708 0.13 0.00 4604 1372 0.13 thunderbird
07:51:41 AM 3721 0.10 0.00 4736 1420 0.14 run-mozilla.sh
07:51:41 AM 3725 8.07 0.08 272920 81716 8.01 thunderbird-bin
07:51:41 AM 3835 234.27 0.12 749812 283212 27.76 firefox
07:51:41 AM 3848 0.01 0.00 4608 448 0.04 firefox_cpu_lim
07:51:41 AM 3849 9.11 0.00 1916 588 0.06 cpulimit
07:51:41 AM 3948 9.40 0.03 112288 36312 3.56 plugin-containe
07:51:41 AM 3956 0.13 0.00 18688 7656 0.75 httpd
07:51:41 AM 3965 0.70 0.00 41128 10936 1.07 notification-da
07:51:41 AM 5130 0.13 0.00 1780 636 0.06 sadc
07:51:41 AM 5859 0.19 0.00 3656 812 0.08 pidstat


Now lets talk about two very important tool which will provide different way to view things. Those are called "sadc" and "sadf".I will cover one after another below.

SADC:
It is system activity and data collector daemon.Even w can use it manually too!.Sadc command intened to run behind the sar command.Actually it will write the binary format of the statistics it collect day by day and put into a dir i.e /var/log/sadd,where dd stands for the particular day.As the man page said it can only provide local activity,means runs on the same host it installed.

I am putting here few example stright out of the manual page for clear understanding.Here we go:

/usr/lib/sa/sadc 1 10 /tmp/datafile
Write 10 records of one second intervals to the /tmp/datafile binary file.

/usr/lib/sa/sadc -C Backup_Start /tmp/datafile
Insert the comment Backup_Start into the file /tmp/datafile.


So move onto the next tool called sadf.

SADF:
This tool actually dispaly the collected data by sar in different format.Which is wonderful..because you can fuse your data to various places to get lot many information.It will essentially provide XML,CVS format data .

once again I am putting example stright out of the manual page for easy understanding.Here we go:

sadf -d /var/log/sa/sa21 -- -r -n DEV
Extract memory, swap space and network statistics from system activity file 'sa21', and display them in a format that can be ingested by a
database.

sadf -p -P 1
Extract CPU statistics for processor 1 (the second processor) from current daily data file, and display them in a format that can easily be
handled by a pattern processing command.



Hope this will help.

Cheers!
Bhaskar

Thursday, August 19, 2010

Few tricks and info about sudo

Working in a multi-admin environment ;where more then one administrator controlling servers,as often the case with most of the big corporates.Then you need a mechanism to deal with that which not allowed each other to overlap their work and keep track who is firing what.Sudo is that kind tool ,which is quite indispensable in the multi-admin production environment.

I do not issue any guarantee that this will work for you.

Most of the GNU/Linux distribution come with sudo..if not then please download it through by it(OSes) package manager. It should be in the repository of that distribution.

Once installed a configuration file related to it placed at /etc named sudoers . So you need edit it according to your requirement to get thing going with this tool.

Tool for to edit that file is called "visudo" ..which nothing but a vi/vim editor with a lock..means when someone editing others won't allow to do anything in it.Clear?? right.

You need to called it like this:

root@bhaskar-laptop_08:37:05_Thu Aug 19:/home/bhaskar # visudo

and the file /etc/sudoers should open in it,but with a temporary location and place with a lock.

Ok..now few internals entry need to visit for the sake of clarity of it's function.So here we go:

Suppose we want to allow sudo with some specific host with specific users on it to allow use of sudo.Did I confuse you with the last statement??not worry ...I will explain it in details..read on:

The careful reader will note that there was a bit of a change here. The line used to read jim ALL=(ALL) ALL?, but now there's only one ALL left. Reading the man page can easily leave you quite confused as to what those three ALL??s meant. ALL refers to machines- the assumption is that this is a network wide sudoers file. In the case of this machine (lnxserve) we could do this:

jim lnxserve= /bin/kill, /usr/sbin/jim/

Now let me explain that a host/machine name called "lnxserve" has a user called "jim" and heis entitled to run those two command right side of the "=" .

So what was the (ALL)? for? Well, here;s a clue:

jim lnxserve=(paul,linda) /bin/kill, /usr/sbin/jim/

Yes this line bring another twist into the previous line.Here it says.. a machine called "lnxserv" with a user called "jim" who will be able to run command as paul and linda with specified command mentioned.

That says that jim can (using sudo -u ) run commands as paul or linda. Yes it sometimes necessary to do it because of various reason in the production environment.I not going into that details ,because that might take another whole article to talk about.

This is perfect for giving jim the power to kill paul or linda's processes without giving him anything else. There is one thing we need to add though: if we just left it like this, jim is forced to use sudo -u paul or sudo -u linda every time. We can add a default runas_default:

Defaults:jim timestamp_timeout=-1, env_delete+=BOOP, runas_default=linda

So jim can easily run command as linda by default.I am going to put some line straight out of the man page for clarity:

To get a file listing of an unreadable directory:

$ sudo ls /usr/local/protected

To list the home directory of user yaz on a machine where the file system holding ~yaz is not exported as root:

$ sudo -u yaz ls ~yaz

To edit the index.html file as user www:

$ sudo -u www vi ~www/htdocs/index.html

To view system logs only accessible to root and users in the adm group:

$ sudo -g adm view /var/log/syslog

To run an editor as jim with a different primary group:

$ sudo -u jim -g audio vi ~jim/sound.txt

To shutdown a machine:

$ sudo shutdown -r +15 "quick reboot"

To make a usage listing of the directories in the /home partition. Note that this runs the commands in a sub-shell to make the cd and file redirection
work.

$ sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"


Hope this will help.

Cheers!
Bhaskar

Monday, August 16, 2010

How to properly run fsck on (/) root or other partitions including LVM

As it is an important issue to deal with low level thing in the server archtecture. Being an GNU/Linux administrator/NOC/Ops one has to have the clear cut understanding what they are doing.Because handling the production box require lot of common sense and in depth knowlegde about the platform/OS.

So without much ado lets play with it or let me show you the simple tricks.

I do not issue any guarantee that this will work for you.

So the first question come into the mind why the hell you need to check the filesystem?? Specially the root(/) part of it...sound pretty dull and boring...huh..please don't ignore this.You know ignorance is a sin...so do not commit it.

Now filesystem can be corrupted in various ways..few common ways are :

1) Not properly shutdown the server(although most of the cases journaling will do the healing)

2) Sudden power cut left your system down with lot of processing going on

3)Somebody has done something special(bad sense) to corrupt the data on that particular partition.

It is a bad idea and not recommended to run fsck(yes,this is the inbuilt tool you need to use)the mounted partition or drive.So don't do that.

Now, running fsck on other partition like /home,/var,/usr ...

First and foremost thing to be done is get into a single user mode..how do you do that?

ok once you type init 1 at the terminal prompt you will be taken to the singe user mode.From there simply unmount the partions as show below:

root@bhaskar-laptop_08:16:36_Mon Aug 16:/home/bhaskar # init 1 ---> this will bring to the single user mode

root@bhaskar-laptop_08:16:36_Mon Aug 16:/home/bhaskar # umount /dev/sda2 ---> assuming this partion hold the /home section.

Now run the fsck:


root@bhaskar-laptop_08:18:02_Mon Aug 16:/home/bhaskar # fsck -yfv /dev/sda2


Ok..let me explain the flags or switch I passed with the fsck .

y------> it will try to detect and fix any filesystem related corruption without manual intervention.

f-----------> this will force check even the system check says it's clean.

v--------> It will provide you the verbose explanation what that comming going through on the terminal screen.

Now a major problem in our hand. That we find out that root(/)partition of the filesystem gor corrupted due to some reasons.So we need to fix that issue to get back the system as soon as possible on the track.

For this kind of problem..it significant that on a mounted system you just cannot run fsck...as I said earlier..becauase it will corrupt the data on it.So we need a installation cd/dvd for our rescue. The first cd/dvd will do the job for us or get a systemrescuecd to do that.

Once you boot with one of those cd/dvd and put the below text at the command prompt it presents:

#linux rescue nomount

Now once you fire that one you are on the prompt so you can begin work on that.First we need to do is fire a mknod command.Now ask me why need to do that???

Because we had passed the option nomount in the last section so it will not parse any file system or it will not initialize any filesystem or create any device to operate on.If you try to run fsck now it will fail.

So to run correctly the fsck to on a filesystem we need to create device file for that.For that we need to run mknod.But to use mknod we need to know the Major number and Minor number of the device.Lets get those number...wait before that I need to tell you few thing about what Major number and Minor number of a device and how it signifies.

What is Major Number and Minor number??

Traditionally, the major number identifies the driver associated with the device. For example, /dev/null and /dev/zero are both managed by driver 1, whereas virtual consoles and serial terminals are managed by driver 4; similarly, both vcs1 and vcsa1 devices are managed by driver 7. Modern Linux kernels allow multiple drivers to share major numbers, but most devices that you will see are still organized on the one-major-one-driver principle.

The minor number is used by the kernel to determine exactly which device is being referred to. Depending on how your driver is written, you can either get a direct pointer to your device from the kernel, or you can use the minor number yourself as an index into a local array of devices. Either way, the kernel itself knows almost nothing about minor numbers beyond the fact that they refer to devices implemented by your driver.

So it's clear?? right.lets move on we need to find out the major number and minor number of the device to run mknod:

root@bhaskar-laptop_08:42:30_Mon Aug 16:/home/bhaskar # ls -al /dev/sda
brw-rw---- 1 root disk 8, 0 Aug 16 07:15 /dev/sda

See it will look like this...as 4the and 5th column holds the major number and minor number.Now create the device file:

#mknod /dev/sda b 8 0

It will create the device file.Once it's done you are safe to run fsck on that particular partition holding your root(/) filesystem.

#fsck -yfv /dev/YourRootPartition(sda,hda,....)

Now lets have some fun with LVM.

We need few tools to manipulate that kind of partition which will provide the lvm package within the os or in come inbuilt with other rescue cd.

We need to find out physical disk,volume group and logical partition ..where we are going to run fsck..right?

pvscan :Physical scanning of particular disk

root@bhaskar-laptop_08:44:06_Mon Aug 16:/home/bhaskar # pvscan
PV /dev/sda8 VG bhaskarlaptop lvm2 [46.15 GiB / 21.15 GiB free]
Total: 1 [46.15 GiB] / in use: 1 [46.15 GiB] / in no VG: 0 [0 ]

vgscan :Volume group scanning

root@bhaskar-laptop_08:50:24_Mon Aug 16:/home/bhaskar # vgscan
Reading all physical volumes. This may take a while...
Found volume group "bhaskarlaptop" using metadata type lvm2

lvscan :Logical volume scanning

root@bhaskar-laptop_08:52:00_Mon Aug 16:/home/bhaskar # lvscan
ACTIVE '/dev/bhaskarlaptop/data' [25.00 GiB] inherit

Now it is not activates then you need to activate the specific logical volume like this:

#lvchange -ay "yourLogicalVolume"

The final step:

Run the fsck on logical volume:

#fsck -yfv /YourLogicalVolume


Hope this will help.

Cheers!
Bhaskar