jim567
作者jim567·2014-04-18 10:03
系统架构师·上海天玑科技股份有限公司

转帖收集信息的脚本

字数 25421阅读 5778评论 0赞 0

#########################################################################################
#                                                                                       #
#   This script is writed by Jason Liang.                                               #
#                                                                                       #
#   I shall be greatly honoured by helping you to collect some system configurations.   #
#                                                                                       #
#                                                          updated at 2013/03/12        #
#                                                                                       #
#########################################################################################
ksh
clear
echo "n"
echo "Start to collect system logs !!n************************************"
echo "It will take 3 ~ 5 minutes, please take a rest !!n"
alogdir=`pwd`/`hostname`_logs                                   # $alogdir is which directory all stdout goes.
alogfile=$alogdir/`hostname`-`date +%F`.log                     # $alogfile is where all stdout goes.
# make log directory #
     mkdir $alogdir &>/dev/null 2>&1
# end of make log directory #
mt=$(lsattr -El sys0|grep modelname|cut -f2 -d","|cut -c"1-8")  # $mt is the system's machine type.
sn=$(lsattr -El sys0|grep systemid|cut -f2 -d","|cut -c"3-9")   # $sn is the system's serial number.
echo "Machine Type:"'011'"Serial Number:"'011'"Hostname:">$alogfile
echo $mt'011'$sn'011''011'$(hostname)>>$alogfile

############################
## Collect System Devices ##
############################
echo >>$alogfile;echo "************************************">>$alogfile;echo >>$alogfile
echo "Collecting System Devices ..."
echo "System Devices">>$alogfile;banner "" >>$alogfile
echo "#lparstat -i">>$alogfile;lparstat -i>>$alogfile;banner "" >>$alogfile
echo "#prtconf">>$alogfile;prtconf>>$alogfile 2>/dev/null;banner "" >>$alogfile
echo "#lsslot -c phb">>$alogfile;lsslot -c phb>>$alogfile 2>&1;banner "" >>$alogfile
echo "#lsslot -c pci">>$alogfile;lsslot -c pci>>$alogfile 2>&1;banner "" >>$alogfile
echo "#lscfg -vp">>$alogfile;lscfg -vp>>$alogfile;banner "" >>$alogfile

##############################
## Collect System IP Config ##
##############################
echo >>$alogfile;echo "************************************">>$alogfile;echo >>$alogfile
echo "Collecting System IP Config ..."
echo "System IP Config">>$alogfile;banner "" >>$alogfile
## check hostname config ##
ping -c 1 `hostname` > /dev/null 2>&1
if [ $? -eq 1 ]
then
        echo "The hostname did not be writed in /etc/hosts !!nPlease check and correct it !!">>$alogfile;banner "" >>$alogfile
fi
if [ $(uname -n) != $(hostname) ]
then
        echo "The hostname on system ODM configuration mismatch!!"
        uname -n `hoatname`
        echo "Corrected !!"
fi
## end check hostname config ##
echo "#cat /etc/hosts">>$alogfile;cat /etc/hosts>>$alogfile;banner "" >>$alogfile
echo "#lsattr -El inet0">>$alogfile;lsattr -El inet0>>$alogfile;banner "" >>$alogfile
## check network adapters properties ##
for eth in $(netstat -in|awk '{print $1}'|grep en|uniq|xargs|sed "s/en/ent/g")
do
        echo "#lsattr -El $eth">>$alogfile;lsattr -El $eth>>$alogfile;banner "" >>$alogfile
done
## end of check network adapters properties ##
echo "#netstat -i">>$alogfile;netstat -i>>$alogfile;banner "" >>$alogfile
echo "#netstat -in">>$alogfile;netstat -in>>$alogfile;banner "" >>$alogfile
echo "#netstat -rn">>$alogfile;netstat -rn>>$alogfile;banner "" >>$alogfile
echo "#entstat -v">>$alogfile 2>/dev/null;netstat -v>>$alogfile 2>/dev/null;banner "" >>$alogfile

###################################
## Collect System Storage Config ##
###################################
echo >>$alogfile;echo "************************************">>$alogfile;echo >>$alogfile        
echo "Collecting System Storage Config ..."
echo "Storage Config">>$alogfile;banner "" >>$alogfile
echo "#lsdev -Cc disk">>$alogfile;lsdev -Cc disk>>$alogfile;banner "" >>$alogfile
## check disks properties ##
#lspv|awk '{print "lsattr -El",$1}'|sh
for disk in $(lspv|awk '{print $1}'|xargs)
do
        echo "#lsattr -El $disk">>$alogfile;lsattr -El $disk>>$alogfile;banner "" >>$alogfile
done
## end of check disks properties ##
## check DS4000 linked path ##
if [ `lsdev -Cc disk|grep -ic mpio` -ne 0 ]
then
        echo "#mpio_get_config -Av">>$alogfile;mpio_get_config -Av>>$alogfile;banner "" >>$alogfile     ## If MPIO is enable then use MPIO command
fi
if [ `lsdev -Cc disk|grep -ic "Disk Array"` -ne 0 ]
then
        echo "#fget_config -Av">>$alogfile;fget_config -Av>>$alogfile;banner "" >>$alogfile             ## If RDAC is enable then use RDAC command
fi
## end of check DS4000 linked path ##
## check EMC disk linked path ##
if [ `lspv|grep -ic hdiskpower` -ne 0 ]
then
        echo "#powermt display">>$alogfile;powermt display>>$alogfile;banner "" >>$alogfile
fi
## check EMC disk linked path ##
echo "#lspath">>$alogfile;lspath>>$alogfile;banner "" >>$alogfile;banner "" >>$alogfile 
echo "#lspv">>$alogfile;lspv>>$alogfile;banner "" >>$alogfile
echo "#lsvg -o|lsvg -i">>$alogfile;lsvg -o|lsvg -i>>$alogfile;banner "" >>$alogfile
echo "#lsvg -o|lsvg -il">>$alogfile;lsvg -o|lsvg -il>>$alogfile;banner "" >>$alogfile
echo "#lsfs">>$alogfile;lsfs>>$alogfile;banner "" >>$alogfile
echo "#df -g">>$alogfile;df -g>>$alogfile;banner "" >>$alogfile

###################################
## Collect System Installed Lpps ##
###################################
echo >>$alogfile;echo "************************************">>$alogfile;echo >>$alogfile        
echo "Collecting System Installed Lpps ..."
echo "System Installed Lpps">>$alogfile;banner "" >>$alogfile
## check oslevel ##
if [ `oslevel -r|cut -f1 -d"0"` > 51 ]
then
        if [ `oslevel -r|cut -f2 -d"-"` > 08 ]
        then
                echo "#oslevel -s">>$alogfile;oslevel -s>>$alogfile;banner "" >>$alogfile  ## IF AIX Version after 5300-04 then use new command "oslevel -s"
        else
                if [[ `oslevel -r|cut -f1 -d"0"` > 52 ]] && [[ `oslevel -r|cut -f2 -d"-"` > 03 ]]
                then
                        echo "#oslevel -s">>$alogfile;oslevel -s>>$alogfile;banner "" >>$alogfile  ## IF AIX Version after 5300-04 then use new command "oslevel -s"
                else
                        if [ `oslevel -r|cut -f1 -d"0"` > 60 ]
                        then
                                echo "#oslevel -s">>$alogfile;oslevel -s>>$alogfile;banner "" >>$alogfile  ## IF AIX Version after 5300-04 then use new command "oslevel -s"
                        else
                                echo "#oslevel -r">>$alogfile;oslevel -r>>$alogfile;banner "" >>$alogfile  ## IF AIX Version before 5300-04 then use old command "oslevel -r"
                        fi
                fi
        fi
else
        echo "#oslevel -r">>$alogfile;oslevel -r>>$alogfile;banner "" >>$alogfile  ## IF AIX Version before 5300-04 then use old command "oslevel -r"
fi
## end of check oslevel ##
echo "#lslpp -l">>$alogfile;lslpp -l>>$alogfile;banner "" >>$alogfile
echo "#instfix -i">>$alogfile;instfix -i|grep ML>>$alogfile;instfix -i|grep SP>>$alogfile;instfix -i|grep All>>$alogfile;instfix -i|grep No>>$alogfile;banner "" >>$alogfile

######################################
## Collect System Enviroment Config ##
######################################
echo >>$alogfile;echo "************************************">>$alogfile;echo >>$alogfile
echo "Collecting System Enviroment Config ..."
echo "System Enviroment Config">>$alogfile;banner "" >>$alogfile
echo "#ulimit -a">>$alogfile;ulimit -a>>$alogfile;banner "" >>$alogfile
echo "#vmo -L">>$alogfile;vmo -L>>$alogfile;banner "" >>$alogfile
echo "#no -L">>$alogfile;no -L>>$alogfile;banner "" >>$alogfile
echo "#lsattr -El sys0">>$alogfile;lsattr -El sys0>>$alogfile;banner "" >>$alogfile
echo "#env">>$alogfile;env>>$alogfile;banner "" >>$alogfile
echo "#locale -a">>$alogfile;locale -a>>$alogfile;banner "" >>$alogfile

###################################
### Collect System HACMP Config ###
###################################
if [ $(lslpp -l|grep -c "cluster.es") -ne 0 ]   
then
        echo >>$alogfile;echo "************************************">>$alogfile;echo >>$alogfile
        echo "Collecting System HACMP Config ..."
        echo "HACMP Config">>$alogfile;banner "" >>$alogfile
        /usr/es/sbin/cluster/utilities/cllsif > /dev/null 2>&1
        if [ $? -eq 255 ]
        then
                echo "HACMP had been installed, but did not be configed !!">>$alogfile;echo >>$alogfile
        else
                #### start clinfoES deamon #### ** start the clinfoES deamon if it have not started
                if [ $(lssrc -g cluster|grep -c clinfoES) -eq 0 ]
                then
                        startsrc -s clinfoES
                fi
                #### end of start clinfoES deamon ####
                echo "#lssrc -g cluster">>$alogfile;lssrc -g cluster>>$alogfile;banner "" >>$alogfile
                echo "#/usr/es/sbin/cluster/clstat -o">>$alogfile;/usr/es/sbin/cluster/clstat -o>>$alogfile 2>&1;banner "" >>$alogfile
                echo "#/usr/es/sbin/cluster/utilities/cldump">>$alogfile;/usr/es/sbin/cluster/utilities/cldump>>$alogfile 2>&1;banner "" >>$alogfile
                /usr/es/sbin/cluster/utilities/clsnapshot -c -i -n `hostname`-clsnap-`date +%F` -d ".">/dev/null 2>&1
                sleep 30
                cp /usr/es/sbin/cluster/snapshots/`hostname`-clsnap-`date +%F`.* $alogdir/ 2>/dev/null
        fi
fi
### End of collecting system HACMP config ###

#############################
### Collect System Status ###
#############################
echo >>$alogfile;echo "************************************">>$alogfile;echo >>$alogfile
echo "Collecting System Logs ..."
echo "errpt -a">>$alogfile;errpt -a>>$alogfile;banner "" >>$alogfile
#########
## END ##
#########
echo >>$alogfile;echo "************************************">>$alogfile;echo >>$alogfile
echo " -- END -- ";echo " -- END -- ">>$alogfile;echo>>$alogfile
echo "Collected Date: "`date +%F1`>>$alogfile
PWD_OLD=`pwd`
cd $alogdir
tar -cf ./`hostname`-`date +%F`.tar ./* >/dev/null 2>&1
gzip -9 ./`hostname`-`date +%F`.tar >/dev/null 2>&1
mv ./*.gz $PWD_OLD
cd $PWD_OLD
rm -R $alogdir >/dev/null 2>&1
echo "The package of system configurations has been put in file: "`hostname`-`date +%F`".tar.gz nPlease remember to download the file !"
#find `pwd` -name collect.sh -exec rm {} ;
exit $alogdir,$alogfile,$mt,$sn,$eth
# pwd
/tmp
# ls
.X11-unix                              cel8388626_s3.err                      javacore.20121217.092304.15990940.txt
.com_ibm_tools_attach                  cel8388626_s3.out                      javacore.20121218.020805.15925358.txt
.ctinst.log                            cel8519822_s2.err                      javacore.20121218.021552.16318512.txt
.ipHarvest.log                         cel8519822_s2.out                      javasharedresources
.list_filesets.out                     cel8519822_s3.err                      langlist.2949138
.list_filesets.toc                     cel8519822_s3.out                      langlist.3801176
.netprobe.log                          collect.sh                             langlist.9961500
.oslevel.datafiles                     ctrmc_MDdr.dbg                         localelist.2949138
.sr_migrate.log                        dpi_socket                             localelist.3801176
.strload.mutex                         dtappint.log                           localelist.9961500
.workdir.5832920.10813502_1            errmbatch                              lost+found
.workdir.8585238.6029430_1             errorlog.log                           lvmgs.log
.workdir.8650864.6029562_1             heapdump.20121214.000634.6750416.phd   lvmt.log
.workdir.9502846.6881520_1             heapdump.20121214.011029.9502962.phd   mpio_get_config_lock
.workdir.9699488.9895966_1             heapdump.20121214.091410.2883800.phd   niflogs
08                                     heapdump.20121217.010232.11403456.phd  plglogs
4_aeiw                                 heapdump.20121217.092303.15990940.phd  portmap.file
51                                     heapdump.20121218.020805.15925358.phd  rc.net.out
IBM.CSMAgentRM_dr.sh.dbg               hsapp01_logs                           rc.net.serial.out
SM_OP_-aoyg                            ibmsupt                                rpcbind.file
SM_OPd_aeio                            install_list.2949138                   saved_errmbatch
Spmi_shm_hook.v62                      install_list.3801176                   sf2818166.00000000
Spmi_shm_hook2.v62                     install_list.9961500                   sf5439688.00000000
_Pak7l                                 instfix-XabEa                          sf7077890.00000000
auiml.tmp                              javacore.20121214.000638.6750416.txt   sh9306336.1
autoverify                             javacore.20121214.011029.9502962.txt   shutdown_rsct.out
cel8388626_s2.err                      javacore.20121214.091410.2883800.txt   wsmdata.7274748
cel8388626_s2.out                      javacore.20121217.010234.11403456.txt  xlogfile
#      

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

X社区推广