Monday, December 19, 2011

AIX Shell Scripts


 GETTING VG AND PV INFORMATION
THIS SCRIPT  COLLECTS VOLUME GROUP AND PHYSICAL VOLUME INFORMATION AND COLLECTS THEM IN A FILE 
THIS INFORMATION IS IMOPORTANT AS ONE SCRIPT ON A SERVER WILL PROVIDE ALL THE INFORMATION ABOUT ALL THE VG AND PV UNDER IT 

for x in $(lsvg) ;SELECT ALL THE VOLUME GROUPS
do
echo "************************************"  >> /tmp/lsvg.out ;PUT A START MARKER
echo VG INFORMATION FOR $x >> /tmp/lsvg.out
lsvg -p $x  >> /tmp/lsvg.out ;COLLECT INFO ABOUT DRIVES
lsvg -l $x >> /tmp/lsvg.out ;COLLECT INFO ABOUT LV 
lsvg $x >> /tmp/lsvg.out ;COLLECT DETAIL INFO ABOUT VG
echo "************************************" >> /tmp/lsvg.out
done
for x in $(lspv|awk ‘{print $1}’) ;SELECT ALL PHYSICAL VOLUME
do
echo"************************************" >>  /tmp/lspv.out
lspv $x >> /tmp/lspv.out   ;STORE THE PV INFORMATION
lspv –l $x >> /tmp/lspv.out
echo"************************************" >>  /tmp/lspv.out
done
TO CUT REQUIRED LOG FROM A LARGE LOG FILE
In the script “mm” “dd” “yy” is month date and year respectively , this script is useful if a logfile has large content of everyday logs and we have to fetch log of a specific date for a specific host or string
for x in hostname1 hostname2 hostname3 ...
do
cat |awk '/"mm"\/"dd"\/"yy""/,/END/'|awk /"$x"/,/"
done
TAKING VIO BACKUP TO A REMOTE FILESYSTEM
HN=`hostname`
LOGFILE="/home/padmin/bckvio.log"
EMAILADDR=xyz@abc.com
echo "GATHERING VIOS CONFIGURATION" > $LOGFILE
/home/padmin/gathervios.ksh >> $LOGFILE  2>&1
date >> $LOGFILE 2>&1
/usr/ios/cli/ioscli mount :/ / >> $LOGFILE 2>&1
/usr/ios/cli/ioscli backupios -file //${HN}_mksysb -mksysb >> $LOGFILE 2>&1
if [[ $? -ne 0 ]]
then
  mail -s "ERROR CREATING VIOS BACKUP" $EMAILADDR <
vio bachup for $HN has failed ! Please look into log /home/padmin/bckvio.log !
EOF
fi
/usr/ios/cli/ioscli unmount / >> $LOGFILE 2>&1
COLLECT ALL THE INFORMATION OF A CHILD DEVICE COMING FROM A FC ADAPTER

lsdev -l $1
echo "PARENT DEVICE FOR ** $1 ***"
lsdev -l $1 -F parent
a=$(lsdev -l $1 -F parent)
echo "PARENT DEVICE FOR ** $a ** IS"
lsdev -l $(lsdev -l $1 -F parent) -F parent
b=$(lsdev -l $(lsdev -l $1 -F parent) -F parent)
echo "ALL THE CHILD DEVICES CONNECTED TO DEVICE ** $a **"
lsdev -p $(lsdev -l $1 -F parent)
echo "ALL THE CHILD DEVICES CONNECTED TO DEVICE ** $b **"
lsdev -p $(lsdev -l $(lsdev -l $1 -F parent) -F parent)
fc=$(echo $b|grep -e fcs0 -e fcs1 -e fcs2 -e fcs4 -e fcs5)
ck=${#fc}
if [ $ck -eq 0 ]
then
echo "BACKUP ADAPTER IS NOT FC"
exit
else
echo "PLEASE WAIT WHILE COLLECTING FC COMMUNICATION"
for x in $fc
do
c=5
echo "DATA TRANSFER FOR ** $x ** "
while [ $c -gt 0 ]
do
fcstat $x|awk '/Transmit/,/Words/'
sleep 10
c=$(($c-1))
done
done
fi

COLLECTING MICROCODE INFORMATION
###### THIS SCRIPT COLLECTS INFORMATION ###########
############# AND HOST LISTS ARE IN FILE HOST.LST###########
exportfs –i /suptools
for x in $(cat /home/aixadmin/host.lst)
do
echo $x >> /suptools/coldata.out
ssh $x ls -lasd /suptools
if [ $? == 0 ]
then
ssh $x mount -o rw :/suptools /suptools
echo "************************************************8" >> /suptools/coldata.out
ssh $x /suptools/./coldata >> /suptools/coldata.out
ssh $x umount /suptools
echo "************************************************8" >> /suptools/coldata.out
else
ssh $x mkdir /suptools
ssh $x mount -o rw :/suptools /suptools
echo "************************************************8" >> /suptools/coldata.out
ssh $x /suptools/./coldata >> /suptools/coldata.out
ssh $x umount /suptools
echo "************************************************8" >> /suptools/coldata.out
fi
done
CONTENTS OF coldata
hostname >> /suptools/coldata.out
oslevel -s >> /suptools/coldata.out
lsmcode -r >> /suptools/coldata.out
for dv in $(lsdev -Cc adapter|awk '{print $1}'|grep -e ent -e fcs -e sisscsi)
do
echo $dv >> /suptools/coldata.out
lsmcode -r -d $dv >> /suptools/coldata.out
done
#
CREATING A USER
#############################################################
############ THIS WILL ASK UID AND USER NAME #################
############AND WILL CREATE USER NAME ON THE SERVERS #############
##### LISTED IN THE FILE  "xyz" ########

echo enter user-id followed by user name for eg 30 username
read uid usd
#echo enter password to reset for the user $usd
for x in $(cat xyz)
do

echo creating user $usd on host $x
ssh $x mkuser id=$uid $usd
done
exportfs -i /exportfilesystem
echo enter password to reset for the user $usd
read pas
echo "echo $usd:$pas|chpasswd" > /exportfilesystem/passet.sh
chmod +x /exportfilesystem/passet.sh
for x in $(cat xyz)
do
ssh $x mkdir /exportfilesystem
ssh $x mount current_server:/exportfilesystem /exportfilesystem
ssh $x /exportfilesystem/passet.sh
ssh $x umount /exportfilesystem
done

RESETTING A USER LOCKED PASSWD

echo enter user name to reset
read usd
echo this will reset user $usd locked password
chsec -f /etc/security/lastlog -a "unsuccessful_login_count=0" -s $usd
chuser "account_locked=false" $usdFINDS OUT FILE SYSTEM UTILIZATION
THIS SCRIPT FINDS AND TELLS YOU WHICH FILE SYSTEM ARE UTILIZING SPACE BOVE THAN THRESHOLD SET BY YOU

h=$(hostname)
df -gt |grep -v Filesystem|grep -v proc|while read out
do
fs=$(echo $out|awk '{print $5 }'|cut -f1 -d%)
if [ "$fs" -gt 90 ]; then
echo "***********************************"
echo FILE SYSTEM LARGER THAN 90% ON $h ARE
echo $out
echo "***********************************"
fi
done
GETTING PORT ADDRESS FOR SERVICES
THIS SCRIPT CALCULATES AND SHOWS WHICH PORT IS USED BY WHICH SERVICE ,VERY IMPORTANT SCRIPT  FOR ALL AIX ADMINISTRATORS

for x in $(netstat -Aan|grep LISTEN|awk '{print $1}')
do
a=$(netstat -Aan|grep LISTEN|grep $x|awk '{print $5}'|cut -f2 -d .)
b=$(rmsock $x tcpcb|awk '{print $9}')
echo PORT $a is used by
ps -ef |grep $b
done
SCRIPT 1 – FINDING USER’S PASSORD EXPIRE DATE
############################################################################
THIS SCRIPT WILL ASK A USER NAME AND TELL WHEN ITS PASSWORD WILL  EXPIRE
#I HAD NOT MADE IT VERY SMOOTH BUT STILL IT SOLVES A VERY BIG THING
################################################################################
echo enter user name  ; PROVIDE THE USER NAME
read uame
lstup=$(pwdadm -q $uame|grep -e lastupdate|cut -f2 -d=)
echo LAST PASSWORD UPDATED FOR USER $uame ON >> /tmp/pwexp.out
echo $lstup| perl -e 'print localtime(<>) . "\n";' >> /tmp/pwexp.out 
mxag=$(lsuser -a maxage $uame|cut -f2 -d=)
pwexp=$(expr 604800 \* $mxag)
pwexp=$(($lstup + $pwexp))
echo PASSWORD EXPIRE DATE FOR USER $uame >> /tmp/pwexp.out
echo $pwexp| perl -e 'print localtime(<>) . "\n";' >> /tmp/pwexp.out
cat /tmp/pwexp.out ;THE OUTPUT IS STORED IN pwexp.out FILE
echo $usd:test@1234|chpasspw