Saturday, June 2, 2012

Finding Start time of a Linux Process

In Linux, finding Starting time of a process using 'top' output will always tend to confuse us. Below is a sample 'top' output of a bunch of 'cpio' process which are running on a Server. The TIME+ column shows some time but it is quite confusing to interpret.

Following are the command-set that I use to find actual Start-time of a Process and how long it runs:

[root@linuxhost ~]# ps -eo pid,lstart,cmd | grep -v grep | grep 14115
14115 Sat Jun  2 01:15:38 2012 cpio -pdmu /NA_cdb01_ud4001
[root@iss-365-tdb02 ~]# date
Sat Jun  2 02:01:41 PDT 2012
[root@linuxhost ~]# ps -eo pid,etime,cmd | grep -v grep | grep 14115
14115       46:23 cpio -pdmu /NA_cdb01_ud4001
[root@iss-365-tdb02 ~]#

The above output shows the Process with PID 14115 started at 01:15:38 AM PDT and it is running for more than 45 minutes.

Friday, June 1, 2012

Script to generate file-system usage report

This script is developed specifically for checking the File-system usage of SAN Mounts on Linux or any UNIX flavors. 
However this can be used to check any Unix filesystem such as /var, /opt, /root etc. This script takes Access, Modified and Change Time as parameters on the specified Mount points and followed by an E-mail address. Upon execution, it will send you the resultant output of the script to the E-mail address that you specified in sorted form with the total size of matching files. In addition a copy of the script output will be stored on the path where you executed the script in the following format: Hostname-Month-Day-Year.

URL to download:

Supported platforms: Any Unix platform with Perl version 5.x or above installed.

How to use:
The syntax for executing this script is as follows:

# [-t]  [-a <value> -m <value> -c <value>]  <Mount points  separated by space>
“-t” for Total disk space
“-a” for access time
“-m” for modification time
“-c” for change time

Upon executing the above command will prompt you to enter the E-mail address to which the file-system usage report needs to be sent. Please note the switch “-t” is optional whereas the other switches “ -a, -m, -c “ are must (atleast one or more). You can give multiple filesystem pathnames separated by space but I suggest giving just one in-order to avoid confusion in sorted output; where the files will be sorted in accordance to its size.

Few Sample Syntax:
# perl -t -a 1000 /san_mount1      <-- List Files which are accessed 1000 days before.

# perl -t -c 1000 /Netapp_filer_mount2  <-- Files which are changed 1000 days before.

# perl -t -m 300  /var                <-- Files modified 300 days before in /var

# perl -t -a 500 -m 750 /u01      <-- Files which are accessed 500 days before and modified 750 days before on /u01.

# perl -t -a 365 /san_mnt1 /san_mnt2     <-- Files which are accessed 365 days before on 2 SAN mounts

How it works:
This script uses &wanted subroutine which comes along with standard Perl Module “File::Find” for traversing through all the files in a desired filesystem. For each file it finds, it checks whether it matches with the parameters supplied and if it is true, it will output the file information along with file size information.  This is a non-intrusive script, as this is equivalent to executing a ‘find’ command.