Search This Blog

Wednesday, May 25, 2011

How Find out number of Machines (IP address) connected to Linux Server?

Use below Command to find out number of Machines connected to Server.

#netstat -nat | awk '{ print }' | cut -d: -f1 | sed -e '/^$/d' | uniq

Tuesday, May 24, 2011

How to find VM guests having Network issue.

This has helped me for finding machines having network issues.

Such machines can then be tracked and further analyzed to find the root cause behind the network issue.

First You will need to login to your VM server.
Issue following command.
watch -n 1 -d netstat -i
Now observe Parameters in Bold.
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
If you find any of above (In bold only ) parameter value to be non 0 and continuously increasing Then this might be an indication of network problem in your vm guest.
Below is typical example of vm machine having network problem.
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
vif22.0 1500 0 0 0 0 0 0 0 39072827 0 BMRU
vif122.0 1500 0 0 0 0 0 0 0 37392429 0 BMRU
vif276.0 1500 0 0 0 0 0 0 0 22717649 0 BMRU

As you can observe Packet are getting dropped while transmitting. So all you need to do is
find the associated vm guests to that virtual interface.
This can be done using following command.

ps -ef | grep tap122.0 (Notice here vif is replaced with tap).
output will contain the name of vm guest having network issue.


You may use following script to find the vm guests.

#!/bin/bash

FIND=`netstat -i | grep vif* | awk '{ if ($10 > 100) print $1":"$10}'`

if [ -z "$FIND" ]
then
echo "No Packet drop (More than 100)"
exit
fi

for I in $FIND
do
Search=`echo $I |awk -F ":" '{print $1}' |awk -F "vif" '{print "tap"$2}'`
if [ -z "$FIND" ]
then
echo "No Interface Found"
exit
fi
ps -ef | grep $Search | grep -v grep | awk '{print $12}'
done

Monday, May 23, 2011

Calling one linux scipt from another.

This might not be the general practice being followed by script writer .
Most of the time it is recommended to write a function inside a script and call it whenever necessary.


Create script.sh and test.sh in /usr/local/sbin

Parent Script.
# cat script.sh
# script.sh file
[[ -f /usr/local/sbin/test.sh ]] && . /usr/local/sbin/test.sh
Var=123
echo "Calling Function"
echo "Value of Var is $Var"
my_test
echo "Returning the control"

Child Script.
# cat test.sh
my_test()
{
echo "Just testing here:)"
echo "Value of Var is $Var"
}

Now execute the parent script.
./script.sh

# ./script.sh
Calling Function
Value of Var is 123
Just testing here:)
Value of Var is 123
Returning the control

All about ssh

A good article over ssh and its configuration file can be found here.

http://www.thegeekstuff.com/2011/05/openssh-options/comment-page-1/#comment-104670

Monday, May 9, 2011

How to find VNC port for Guest machines running on Oracle VM.

Use below script for finding VNC port of all Guest Machines running on the Oracle VM server.

xm list > temp
y=`xm list | wc -l`

z=`expr $y - 2`

while [ $y -gt 1 ]
do
x=`awk -F" " '{print $1}' temp | sed -n "${y}p"`
echo -e '\E[32m'
y=`expr $y - 1`
xm list $x -l |grep 0.0:|awk -v Host=$x -F[:\)] '{print "Vnc Port for " Host " :" $2 }'
echo -e '\E[37m'
done

Sunday, May 8, 2011

Disk Monitoring Using IOZONE.

iozone is a filesystem benchmarking tool.

iozone help us identify disk performance. I would recommend it to test SAN,NAS or Local Harddisk performance.

Step 1:
Download the utility from its official source.
http://www.iozone.org/

Saturday, May 7, 2011

Tweaking bashrc file.

A good article on tweaking bashrc file can be read here.

http://www.novell.com/coolsolutions/tools/17142.html

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.

Thursday, May 5, 2011

How to check a file being used by a process?

It would be a best practice to check if the file is being used by any process before deleting it.

This can be easily done by using lsof utility .

for example if i want to delete a file System.img . I will first check whether it is being used by any process or not.


# lsof System.img
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
qemu-dm 19376 root 10u REG 0,26 80015523840 1763 System.img

As you can see the qemu-dm process is using the file so i better of first find what qemu-dm is doing on the file and then delete it.

Wednesday, May 4, 2011

How to check filesystem type ?

You can run below command to check linux file system.

# df -hT
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3     39G  1.1G   36G   3% /
/dev/sda1     ext3     99M   46M   49M  49% /boot
tmpfs        tmpfs    2.6G     0  2.6G   0% /dev/shm
none         tmpfs    2.5G  328K  2.5G   1% /var/lib/xenstored
NASSERVER01:/
export/share1
               nfs    5.3T  3.0T  2.3T  58% /var/ovs/mount/D0122C0A025346218D9E9574667D34ADNASSERVER01:/export/share2
               nfs    250G  191G   60G  77% /var/ovs/mount/DCB311A73E6E4053A116E02A47D802F8

(
-h : used for human readable output
-T : --print-type
print file system type
)



THe same command can be used for showing POXFIX output( One line)

Just append P.
# df -hTP
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3     39G  1.1G   36G   3% /
/dev/sda1     ext3     99M   46M   49M  49% /boot
tmpfs        tmpfs    2.6G     0  2.6G   0% /dev/shm
none         tmpfs    2.5G  328K  2.5G   1% /var/lib/xenstored
NASSERVER01:/
export/share1    nfs    5.3T  3.0T  2.3T  58% /var/ovs/mount/D0122C0A025346218D9E9574667D34AD 
NASSERVER01:/export/share2 nfs    250G  191G   60G  77% /var/ovs/mount/DCB311A73E6E4053A116E02A47D802F8
 

There are more such examples @ http://www.thegeekstuff.com/2012/05/df-examples/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+TheGeekStuff+%28The+Geek+Stuff%29

Please Leave us with your comments and Queries /Suggestions.
           I will try to reply asap.

Tuesday, May 3, 2011

How to track Application causing Memory Leak using ps command ?

Normally Most of applications uses some part of memory and release it after their operation is over or Application is closed.

However some applications don't just give up memory and leads to memory being utilized heavily.

For RAM consumption simulation i have used a script ( source : http://stackoverflow.com/questions/4964799/write-a-bash-shell-script-that-consumes-a-constant-amount-of-ram-for-a-user-defin )

#!/bin/bash

echo "Provide sleep time in the form of NUMBER[SUFFIX]"
echo " SUFFIX may be 's' for seconds (default), 'm' for minutes,"
echo " 'h' for hours, or 'd' for days."
read -p "> " delay

echo "begin allocating memory..."
for index in $(seq 1000); do
value=$(seq -w -s '' $index $(($index + 100000)))
eval array$index=$value
done
echo "...end allocating memory"

echo "sleeping for $delay"
sleep $delay

saved the script with name /tmp/ramload.sh

As per the script owner it had consumed 570M to 575M physical memory* for the specified time period of 5 minutes.

Ran the command.
# ./ramload.sh
Provide sleep time in the form of NUMBER[SUFFIX]
SUFFIX may be 's' for seconds (default), 'm' for minutes,
'h' for hours, or 'd' for days.
> 5m
begin allocating memory...


You can track such applications using following ps command.

#ps aux --sort rss
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2 0.0 0.0 0 0 ? S< 01:54 0:00 [migration/0]
root 3 0.0 0.0 0 0 ? SN 01:54 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S< 01:54 0:00 [watchdog/0]
root 5 0.0 0.0 0 0 ? S< 01:54 0:00 [migration/1]
root 4732 0.0 0.4 10732 4848 tty7 Ss+ 01:55 0:01 /usr/bin/Xorg :
root 4746 0.0 0.9 24444 9784 ? SN 01:55 0:00 /usr/bin/python
gdm 4756 0.0 1.5 30488 15540 ? Ss 01:55 0:00 /usr/libexec/gd
root 8900 55.9 2.7 32188 28584 pts/1 R+ 23:58 0:25 /bin/bash ./ramload.sh



Run the command after some time.

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 4731 0.0 0.3 27392 3740 ? Sl May03 0:00 /usr/libexec/gdm-rh-security-token-helper
root 4318 0.0 0.4 13256 4692 ? S May03 0:00 python ./hpssd.py
root 4732 0.0 0.4 10732 4848 tty7 Ss+ May03 0:01 /usr/bin/Xorg :0 -br -audit 0 -auth /var/gdm/:0.Xauth -nolist
root 4746 0.0 0.9 24444 9784 ? SN May03 0:00 /usr/bin/python -tt /usr/sbin/yum-updatesd
gdm 4756 0.0 1.5 30488 15540 ? Ss May03 0:00 /usr/libexec/gdmgreeter
root 8900 69.5 5.5 60624 57276 pts/1 S+ May03 0:54 /bin/bash ./ramload.sh


You can observe the last entry which is
/bin/bash ./ramload.sh
Is a reason behind memory utilization.

(
Note:
1) Only few entries are displayed from output due to its size.
2) Normally ps aux --sort pmem is used for sorting the ps output using the memory but it has some bug .
see below link for more info
http://www.linuxquestions.org/questions/showthread.php?p=4344941&posted=1#post4344941
)
From above output we can say that
./ramload.sh
process is using the max memory.You need to fire the command at regular interval to check if the process is culprit behind memory crisis.


Monday, May 2, 2011

Create File Using dd command.

In linux you can create a file and also define its size in advance.
Unlike windows OS when you create the file it get 0 kb as default size ,In linux you can specify the file size .

for example.
#dd if=/dev/zero of=/tmp/Sample.dat bs=1M count=1024

Above command will create a file called Sample.dat of size 1 GB.

For More Information Check .

http://www.linuxquestions.org/questions/showthread.php?p=4347966#post4347966

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.