Sunday, June 26, 2011

Perl script to find Broken Symbolic links

Creating Symbolic links across filesystem are very handy but at the same time, they can be a real pain when they got broken. At my work I often seen Developers wasting their time in fixing application issues, which was fundamentally caused by broken symbolic links. So I came out with this script.


Upon execution of this script, it will prompt you to enter the filesystem paths as parameters. Once done, it will report all the broken symbolic links with count number.


I used the Perl module File::Find (comes default with any Perl package) for traversing through all the filenames in the specified directories and report the broken links. For each file it finds, it calls the &wanted subroutine, which in turn uses the Stat function to match the symbolic link files which are broken. To be honest, I grabbed this logic from an online book on Perl programming.


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


EXAMPLE

[root@hostxyz opt]# perl check_broken_link.pl

Enter the filesystem path (like /etc /opt /var) : /var /etc /usr /home
Disconnected Link => /var/lib/jbossas/server/production/lib/jboss-remoting.jar -> /usr/share/java/jboss-remoting.jar
Disconnected Link => /var/lib/jbossas/server/default/lib/jboss-remoting.jar -> /usr/share/java/jboss-remoting.jar
Disconnected Link => /etc/alternatives/jaxws_api -> /usr/share/java/glassfish-jaxws.jar
Disconnected Link => /etc/alternatives/jaxws_2_1_api -> /usr/share/java/glassfish-jaxws.jar
Disconnected Link => /etc/alternatives/jaxb_2_1_api -> /usr/share/java/glassfish-jaxb.jar
Disconnected Link => /etc/alternatives/jaxb_api -> /usr/share/java/glassfish-jaxb.jar
Disconnected Link => /usr/share/java/jaxws_api.jar -> /etc/alternatives/jaxws_api
Disconnected Link => /usr/share/java/jaxb_api.jar -> /etc/alternatives/jaxb_api
Disconnected Link => /usr/share/java/jaxws_2_1_api.jar -> /etc/alternatives/jaxws_2_1_api
Disconnected Link => /usr/share/jbossas/client/jboss-remoting.jar -> /usr/share/java/jboss-remoting.jar


Total number of Disconnected links: 10
[root@hostxyz opt]#


SCRIPT

#!/usr/bin/perl
use File::Find ();
use vars qw/*name *dir *prune/;
my ($cnt,$i,$cnt_sub) = (0,0,0);
print "\n";
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
print "Enter the filesystem path (like /etc /opt /var) : ";
my $arr = <>;
chomp($arr);
print "\n";
my @inpts = split(/ /, $arr);


foreach(@inpts)
{

File::Find::find({wanted => \&wanted}, $inpts[$i] ); # Calling wanted subroutine which use stat function to match broken links
$cnt = $cnt_sub + $cnt;
$i++;
$cnt_sub = 0;
}
print "Total number of Disconnected links: $cnt \n\n";


sub wanted {
if (-l $_) {
@stat = stat($_);
if ($#stat == -1)
{
$flname = `ls -l $name`;
($flperm, $numlnk, $flown1, $flown2, $dt, $mnth, $tm1, $tm2, $cfnm, $ar, $dsfl) = split /\s+/, $flname;
print "Disconnected Link => $cfnm $ar $dsfl\n\n";
$cnt_sub++;
  }
 }
}


URL to download the script :  http://db.tt/b7so1QYo

Best way to check Hyper-threading feature in Linux

Run "dmidecode -t processor" and grep for the entry "HTT" from the result.


Sample output:

[root@server10 ~]# dmidecode -t processor | grep HTT
HTT (Hyper-threading technology)
HTT (Hyper-threading technology)
[root@server10 ~]#

So if Hyper-threading is enabled, the count of Logical Processors would be double the number of CPU cores that you got on the server.
To find the number of CPU cores, you either use "dmidecode -t processor" command or check the number of Physical IDs from "/proc/cpuinfo" output.

Please be aware the “ht” entry in /proc/cpuinfo output is a confusing flag. It may be definite for CPU with single core but not for multi-core CPU. Enabling HT should be done at BIOS level.

Sunday, June 19, 2011

VMware ESXi basic command reference

To find ESX software version and build:
# vmware -v
  VMware ESXi 4.1.0 build-348481
# vmware -l
  VMware ESXi 4.1.0 Update 1


To know the Hostname and IP Addess:
# hostname -s
   vmesxi-ht1
# hostname -i
  171.12.13.14


To find list of VMs running:
# vm-support -x
VMware ESX Support Script 1.33
Available worlds to debug:
wid=6342 hostlx03
wid=608998 cactty01


# vim-cmd vmsvc/getallvms
Vmid Name File Guest OS Version Annotation
144 cactty01 [datastore1] cacllm01-d2_template/cacllm01-d2_template.vmx rhel5_64Guest vmx-07 Linux host with RHEL 5.6 64bit OS with JDK 1.6
48 hostlx03 [datastore1] htblsb03/htblsb03.vmx rhel5Guest vmx-07
#


To see the running processes
# esxtop


To get the list of services:
# chkconfig --list
DCUI on
TSM-SSH on
TSM on
.
[ Output truncated]
#


To check NIC properties:
# esxcfg-nics -l
Name PCI Driver Link Speed Duplex MAC Address MTU Description
vmnic0 0000:10:00.00 bnx2 Up 1000Mbps Full 5c:f3:fc:21:b5:e4 1500 Broadcom Corporation Broadcom NetXtreme II BCM5709 1000Base-SX
vmnic1 0000:10:00.01 bnx2 Up 1000Mbps Full 5c:f3:fc:21:b5:e6 1500 Broadcom Corporation Broadcom NetXtreme II BCM5709 1000Base-SX
vusb0 Pseudo cdc_ether Up 0Mbps Half 5e:f3:fc:23:b5:e7 1500 Unknown Unknown
#
# esxcfg-vmknic -l
Interface Port Group/DVPort IP Family IP Address Netmask Broadcast MAC Address MTU TSO MSS Enabled Type
vmk0 Management Network IPv4 10.20.21.160 255.255.255.0 10.20.21.255 5c:f3:fc:21:b5:e4 1500 65535 true STATIC


# esxcfg-vswitch -l
Switch Name Num Ports Used Ports Configured Ports MTU Uplinks
vSwitch0 128 5 128 1500 vmnic0
PortGroup Name VLAN ID Used Ports Uplinks
VM Network 4095 2 vmnic0
Management Network 0 1 vmnic0
Switch Name Num Ports Used Ports Configured Ports MTU Uplinks
vSwitch2 128 3 128 1500 vmnic1
PortGroup Name VLAN ID Used Ports Uplinks
VM Network 3 0 1 vmnic1
#


# vsish -e get net/pNics/vmnic0/properties
properties {
Driver Name:bnx2
Driver Version:2.0.7d-3vmw
Driver Firmware Version:5.2.3 NCSI 2.0.10
System Device Name:vmnic0
Module Interface Used By The Driver:vmklinux26
Device Hardware Cap Supported:: 0x3c032b -> VMNET_CAP_SG Device Software Cap Activated:: 0x800000 -> VMNET_CAP_RDONLY_INETHDRS
Interrupt Vector:0xff
Link Up:1
Speed (Mb/s):1000
Full Duplex:1
Uplink Port ID:0x01000002
.
[ Output truncated ]
 #
PS: As there are already several well-written article on this subject, I don't wanna put more effort on it. So here am recommending couple of links which am impressed with:
http://b2v.co.uk/b2vguide2vmware3.htm
http://www.vmware.com/support/developer/vcli/vcli41/doc/reference/index.html