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

QUICK REFERENCE FOR LDAP CONFIGURATION IN AIX


1. Create the first ldap server

To create a ldap server type command

mksecldap -s -a cn=admin -p adminpwd -S rfc2307aix

2. Add/Create a new domain

To Add a new domain named dcmdata.com

mksecldap -s -a cn=admin -p adminpwd -S rfc2307aix -d "dc=dcmdata,dc=com"

2. If you want to create a container(OU -orgainization unit)

To add a OU in domain dcmdata.com

mksecldap -s -a cn=admin -p adminpwd -S rfc2307aix -d /

"ou=users,dc=dcmdata,dc=com"

4. Creating a ldap client in ldap server

To add a client in ldap server dcmdata.com

mksecldap -c -h 193.9.200.229 -a cn=admin -p adminpwd -d "dc=dcmdata,dc=com"

5. Create a user in ldap server

To add a user shivas in doman dcmdata.com

mksecldap -c -h 193.9.200.229 -a cn=admin -p adminpwd -d "dc=dcmdata,dc=com"

-u shivas

6. CReating the first user (type ldap) in Aix and add in ldap

To add a user in Aix

mkuser aswe

To add users entry in ldap

mksecldap -c -h 193.9.200.229 -a cn=admin -p adminpwd -d "dc=dcmdata,dc=com" -u aswe

 
To add a user after making ldap server is down

ldapcfg -u "cn=root" -p galaxy123

CREATING AIX MKSYSB ISO BOOTABLE IMAGE

Create a Mksysb image (Assuming that the system has two disk and rootvg contains 1 disk )

Create VG

mkvg -y datavg hdisk1

Create a File system in the new vg 

crfs -v jfs2 -g datavg -a size=10G -m /data

Mount the new file system 

mount /data 

now crete a exclude.rootvg in /etc

echo "/data/" >> /etc/exclude.rootvg

Run mksysb command

mksysb -X -i -e /data/root.mkisysb

Now Create a bootable iso image from mksysb image 

# mkdvd -S -m /root.mksysb

Initializing mkdvd log: /var/adm/ras/mkcd.log...
Verifying command parameters...
0512-054 mkdvd: File /root.mksysb does not exist or is empty.
# mkdvd -S -m /root.mkisysb
Initializing mkdvd log: /var/adm/ras/mkcd.log...
Verifying command parameters...
Creating temporary file system: /mkcd/cd_fs...
Populating the CD or DVD file system...
Building chrp boot image...
Copying backup to the CD or DVD file system...
......................................
Creating temporary file system: /mkcd/cd_images...
Creating Rock Ridge format image: /mkcd/cd_images/cd_image_163898
Running mkisofs ...
.......................................
mkrr_fs was successful.
Making the CD or DVD image bootable...

Removing temporary file system: /mkcd/cd_fs...
# pwd
/mkcd/cd_images
# ls -l
total 3236104
-rw-r--r--    1 root     sys      1656872960 Feb 25 01:50 cd_image_163898
drwxrwx---    2 root     system          512 Feb 25 01:44 lost+found
#

AIX PAGING SPACE


# lsps -a
Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type
hd6             hdisk0            rootvg         512MB    17   yes   yes    lv
CREATE A NEW LV TO USE FOR PAGING SPACE 

# mklv -t paging rootvg 5
pagelv00

SEE CURRENT PAGING SPACES WHICH ARE  REGISTERED 

#
# cat /etc/swapspaces
* /etc/swapspaces
*
* This file lists all the paging spaces that are automatically put into
* service on each system restart (the 'swapon -a' command executed from
* /etc/rc swaps on every device listed here).
*
* WARNING: Only paging space devices should be listed here.
*
* This file is modified by the chps, mkps and rmps commands and referenced
* by the lsps and swapon commands.
hd6:
        dev = /dev/hd6


ENABLING A PAGING SPACE 


# swapon /dev/pagelv00
# lsps -a
Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type
pagelv00        hdisk0            rootvg         640MB     1   yes    no    lv
hd6             hdisk0            rootvg         512MB    17   yes   yes    lv
#
DISABLING A PAGING SPACE 


# swapoff /dev/pagelv00
# lsps -a
Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type
pagelv00        hdisk0            rootvg         640MB     0    no    no    lv
hd6             hdisk0            rootvg         512MB    17   yes   yes    lv
#
CREATING A PAGING SPACE THROUGH mkps 


# mkps -a -n -s3 rootvg
paging00
# lsps -a
Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type
paging00        hdisk0            rootvg         384MB     1   yes   yes    lv
pagelv00        hdisk0            rootvg         640MB     0    no    no    lv
hd6             hdisk0            rootvg         512MB    17   yes   yes    lv
MKPS AUTOMATICALLY ADDS PAGING SPACE IN /etc/swapspaces 


# cat /etc/swapspaces
* /etc/swapspaces
*
* This file lists all the paging spaces that are automatically put into
* service on each system restart (the 'swapon -a' command executed from
* /etc/rc swaps on every device listed here).
*
* WARNING: Only paging space devices should be listed here.
*
* This file is modified by the chps, mkps and rmps commands and referenced
* by the lsps and swapon commands.
hd6:
        dev = /dev/hd6


paging00:
        dev = /dev/paging00

CHANGING PAGING SPACE 

INCREASING PAGING SIZE 

# lsps -a
Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type
paging00        hdisk0            rootvg         384MB     1   yes   yes    lv
pagelv00        hdisk0            rootvg         640MB     0    no    no    lv
hd6             hdisk0            rootvg         512MB    17   yes   yes    lv


# chps -s 2 paging00


# lsps -a
Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type
paging00        hdisk0            rootvg         640MB     1   yes   yes    lv
pagelv00        hdisk0            rootvg         640MB     0    no    no    lv
hd6             hdisk0            rootvg         512MB    17   yes   yes    lv
#
DECREASING PAGING SPACE 


# chps -d 1 paging00
shrinkps: Temporary paging space paging01 created.
shrinkps: Paging space paging00 removed.
shrinkps: Paging space paging00 recreated with new size.


# lsps -a
Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type
paging00        hdisk0            rootvg         512MB     1   yes   yes    lv
pagelv00        hdisk0            rootvg         640MB     0    no    no    lv
hd6             hdisk0            rootvg         512MB    17   yes   yes    lv
#