Você está na página 1de 5

#!

/bin/ksh

##########################################
# This script is used to collect operating system information from AIX
# Developed for the "MustGather: Crash on AIX" technote
# Property of IBM - author Michael Schneider
##########################################

SCRIPT_VERSION=20111201
##########################################
# FIXES
# 12/01/2011 - Fixed errpt so it now outputs to errpt.out instead of df.out
# - Added ps.out (to capture ps -ef).
##########################################
# Variables
##########################################

S_USERID=
S_OVERRIDE_ROOT=N #Set to Y, or use the argument -R, to override the check for
the root user.

# FUNCTIONS
##########################################
# Determine if root
##########################################
isRoot()
{
print $(date) " AIX_OSINFO:I: Entering isRoot()" | tee -a aix_osinfo.log

S_USERID=`whoami`
if [ $S_USERID = "root" ]
then
print $(date) " AIX_OSINFO:I: Root user confirmed" | tee -a
aix_osinfo.log
else
print $(date) " AIX_OSINFO:W: Non-root user ($S_USERID) has executed
this script!" | tee -a aix_osinfo.log
echo "Non-root user ($S_USERID) has executed this script!" >> emgr.out
print $(date) " AIX_OSINFO:W: The command 'emgr -lv3' will not be
executed. Please rerun this command separately as the root user." | tee -a
aix_osinfo.log
fi

print $(date) " AIX_OSINFO:I: Exiting isRoot()" | tee -a aix_osinfo.log


}

##########################################
# Logging functions
##########################################
startLog()
{
date > aix_osinfo.log 2>&1
print $(date) " AIX_OSINFO:I: Version of this script is :$SCRIPT_VERSION:" |
tee -a aix_osinfo.log
print $(date) " AIX_OSINFO:I: This script is used to collect operating system
information on AIX" | tee -a aix_osinfo.log
}

endLog()
{

print $(date) " AIX_OSINFO:I: Only these files have been automatically
collected into the aix_osinfo_RESULTS.tar.gz file:" | tee -a aix_osinfo.log

if [ $S_USERID = "root" ]
then
print $(date) " AIX_OSINFO:I: emgr.log" | tee -a aix_osinfo.log
fi

print $(date) " AIX_OSINFO:I: ps.out" | tee -a aix_osinfo.log


print $(date) " AIX_OSINFO:I: oslevel.out" | tee -a aix_osinfo.log
print $(date) " AIX_OSINFO:I: lslpp.out" | tee -a aix_osinfo.log
print $(date) " AIX_OSINFO:I: instfix.out" | tee -a aix_osinfo.log
print $(date) " AIX_OSINFO:I: prtconf.out" | tee -a aix_osinfo.log
print $(date) " AIX_OSINFO:I: lparstat.out" | tee -a aix_osinfo.log
print $(date) " AIX_OSINFO:I: lsattr.out" | tee -a aix_osinfo.log
print $(date) " AIX_OSINFO:I: df.out" | tee -a aix_osinfo.log
print $(date) " AIX_OSINFO:I: errpt.out" | tee -a aix_osinfo.log

print $(date) " AIX_OSINFO:I: Please send in all files generated to IBM
support." | tee -a aix_osinfo.log

if [ $S_USERID = "root" ]
then
print $(date) " AIX_OSINFO:I: Additionally collect the rest of the
files required in the MustGather." | tee -a aix_osinfo.log
else
print $(date) " AIX_OSINFO:W: The command 'emgr -lv3' requires root
authority. Please run this command separately and combine this with the other
files generated and what is required in the MustGather." | tee -a aix_osinfo.log
fi

print $(date) " AIX_OSINFO:I: END OF SCRIPT" | tee -a aix_osinfo.log

##########################################
# Create Output Files
##########################################

createOutput()
{
print $(date) " AIX_OSINFO:I: Entering createOutput()" | tee -a
aix_osinfo.log
print $(date) " AIX_OSINFO:I: Creating output files" | tee -a aix_osinfo.log

echo > ps.out


echo > oslevel.out
echo > lslpp.out
echo > instfix.out
echo > prtconf.out
echo > lparstat.out
echo "This file will be empty if the script is run as a non-root user, check
the aix_osinfo.log" > emgr.out
echo > lsattr.out
echo > df.out
echo > errpt.out

print $(date) " AIX_OSINFO:I: Finished creating output files" | tee -a


aix_osinfo.log
print $(date) " AIX_OSINFO:I: Exiting createOutput()" | tee -a aix_osinfo.log
}

##########################################
# TAR | GZIP data
##########################################

compressData()
{
print $(date) " AIX_OSINFO:I: Entering compressData()" | tee -a
aix_osinfo.log

# Build a string to contain all the file names


FILES_STRING="ps.out emgr.out oslevel.out lslpp.out instfix.out prtconf.out
lparstat.out lsattr.out df.out errpt.out"

# Tar/GZip the output files together


print $(date) " AIX_OSINFO:I: Compress output files into
aixperf_RESULTS.tar.gz" | tee -a aix_osinfo.log

S_RET=0 # Reset RET

print $(date) " AIX_OSINFO:I: Executing 'tar -cvs aix_osinf_RESULTS.tar'" |


tee -a aix_osinfo.log

tar -cvf aix_osinfo_RESULTS.tar $FILES_STRING


S_RET=$?

if [ S_RET -ne 0 ]
then
#display error message and do not delete files
print $(date) " AIX_OSINFO:E: Tarball creation failed. Please manually
collect the files generated." | tee -a aix_osinfo.log
else
#continue processing gzip, delete files regardless
S_RET=0 #reset RET

print $(date) " AIX_OSINFO:I: Executing 'gzip aix_osinfo_RESULTS.tar'"


| tee -a aix_osinfo.log
gzip aix_osinfo_RESULTS.tar
S_RET=$?

if [ S_RET -ne 0 ]
then
print $(date) " AIX_OSINFO:E: Gzip creation failed, instead
tarball has been generated." | tee -a aix_osinfo.log
fi

# Clean up the output files now that they have been tar/gz'd.
print $(date) " AIX_OSINFO:I: Remove the temporary output files as they
have now been added to the archive file." | tee -a aix_osinfo.log
rm $FILES_STRING
fi
print $(date) " AIX_OSINFO:I: Exiting compressData()" | tee -a aix_osinfo.log
}

##########################################
# Execute Commands
##########################################

execute()
{
print $(date) " AIX_OSINFO:I: Entering execute()" | tee -a aix_osinfo.log

if [ $S_USERID = "root" ]
then
print $(date) " AIX_OSINFO:I: Executing '/usr/sbin/emgr -lv3'" | tee -a
aix_osinfo.log
/usr/sbin/emgr -lv3 > emgr.out 2>&1
fi

print $(date) " AIX_OSINFO:I: Executing 'ps -ef'" | tee -a aix_osinfo.log


ps -ef > ps.out 2>&1

print $(date) " AIX_OSINFO:I: Executing 'oslevel -s'" | tee -a aix_osinfo.log


oslevel -s > oslevel.out 2>&1

print $(date) " AIX_OSINFO:I: Executing 'lslpp -la'" | tee -a aix_osinfo.log


lslpp -la > lslpp.out 2>&1

print $(date) " AIX_OSINFO:I: Executing 'instfix -ia'" | tee -a


aix_osinfo.log
instfix -ia > instfix.out 2>&1

print $(date) " AIX_OSINFO:I: Executing 'prtconf'" | tee -a aix_osinfo.log


prtconf > prtconf.out 2>&1

print $(date) " AIX_OSINFO:I: Executing 'lparstat -i'" | tee -a


aix_osinfo.log
lparstat -i > lparstat.out 2>&1

print $(date) " AIX_OSINFO:I: Executing 'lsattr -El sys0'" | tee -a


aix_osinfo.log
lsattr -El sys0 > lsattr.out 2>&1

print $(date) " AIX_OSINFO:I: Executing 'df -k'" | tee -a aix_osinfo.log


df -k > df.out 2>&1

print $(date) " AIX_OSINFO:I: Executing 'errpt -a'" | tee -a aix_osinfo.log


errpt -a > errpt.out 2>&1

print $(date) " AIX_OSINFO:I: All commands have been executed." | tee -a
aix_osinfo.log

print $(date) " AIX_OSINFO:I: Exiting execute()" | tee -a aix_osinfo.log


}

#########################################
# Main Method
#########################################
startLog

createOutput

# Get Options
while getopts Rr name
do
case $name in
R) S_OVERRIDE_ROOT=Y;;
r) S_OVERRIDE_ROOT=N;;
esac
done

if [ $S_OVERRIDE_ROOT = "Y" ]
then
print $(date) " AIX_OSINFO:W: You have overrided the confirmation check for
the root user!" | tee -a aix_osinfo.log
echo "Script has been forced to run as if the userid was root." >> emgr.out
S_USERID=root
else
isRoot
fi

execute

# TAR and GZIP commands


compressData

endLog

Você também pode gostar