Sunday, May 26, 2013

SCRIPT TO VIEW BIGIP LTM V10 VIRTUAL SERVER CONFIGURATION.

SCRIPT TO VIEW BIGIP LTM V10 VIRTUAL SERVER CONFIGURATION 

#!/bin/bash
> out.txt
> logcheck.txt
> result.txt
read -p "Enter Username: " user
read -p "Enter Valid Password: " password
if [ -z "${user}" ] || [ -z "${password}" ];   # Exit if no arguments were given.; then
then
echo "Error: Username or Password are empty"
exit $NOARGS
fi ;
read -p "Enter Active Device name: " dev
if [ -z "${dev}" ] ;   # Exit if no arguments were given.
then
echo "Error: Device Name is empty"
exit $NOARGS
fi ;
read -p "Enter Valid VIP IP: " vipip
if [ -z "${vipip}" ] ;   # Exit if no arguments were given.
then
echo "Error: VIP IP is empty"
exit $NOARGS
else
/usr/local/bin/sshpass -p "$password" ssh  "$user"@"$dev" "cat /config/bigip.conf |grep -q $vipip"
errorCode=$?
if [ ${errorCode} -ne 0 ]
then echo "Unable to find the IP in device config.Please confim."
exit $NOARGS
fi ;
fi ;

read -p "Enter Valid VIP Port: " vipipport
echo "$user"
echo "$dev"
echo "$password"
/usr/local/bin/sshpass -p "$password" ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$user"@"$dev" "exit"
errorCode=$?    # checks if the last operation (sqlplus) was completed successfully or not
if [ ${errorCode} -ne 0 ]
then
echo "Unable to connect the Device with the supplied credentials. Please check the Credentials or Device Name."
exit ${CRED_ERR}
else
echo  "Device was connected successfully"
fi
/usr/local/bin/sshpass -p "$password" ssh  "$user"@"$dev" "cat /config/bigip.conf |grep $vipip:$vipipport -A 2 -B 4| egrep 'virtual|pool' | awk '{print "'$1,$2'"}'" >> out.txt
IFS=$'\n';for pool in `cat out.txt |grep pool` ; do /usr/local/bin/sshpass -p "$password" ssh "$user"@"$dev" " b $pool list |grep 'monitor'|uniq | sed 's/\//g'|awk '{print "'$1,$2'"}'" >> out.txt ;done
IFS=$'\n'; for line in `cat out.txt|awk '!x[$0]++'`; do echo "===================================" && /usr/local/bin/sshpass -p "$password" ssh "$user"@"$dev" " b $line list" ; done
FS=$'\n'; for line in `cat out.txt|awk '!x[$0]++'`; do echo "===================================" && /usr/local/bin/sshpass -p "$password" ssh "$user"@"$dev" " b $line show" ; done > result.txt 2>&1

read -p "Do You Want To check The Logs? [y/n]" answer
if [[ $answer =~ ^(yes|y|Y| ) ]]
then
cat out.txt|awk '!x[$0]++'|egrep 'virtual|pool'|awk {'print $2'} >> logcheck.txt
cat result.txt|grep "POOL MEMBER"|awk {'print $4'}|cut -f2 -d"/"|cut -f1 -d ":"|awk '!x[$0]++' >> logcheck.txt
searchvalue=`cat logcheck.txt |xargs| sed 's/ /|/g'`
echo "search value $searchvalue"
/usr/local/bin/sshpass -p "$password" ssh  "$user"@"$dev" "cat /var/log/ltm && zcat /var/log/ltm.* |egrep -w '$searchvalue'"
else
exit
fi