#freeze
 #!/bin/bash
 
 #
 
 set -u
 
 GetYN() {
 	_ANS=""
 	while :
 	do
 		echo -e "$@ [y/n?] \c"
 		read _ANS
 		case "$_ANS" in
 			[yY] | yes | YES | Yes )        return 0 ;;
 			[nN] | no  | NO  | No  )        return 1 ;;
 			* ) echo "Please Enter y or n." ;;
 		esac
 	done
 }
 
 ShowFile () {
 	echo "#### $1 ####"
 	ls -l $1
 	echo "#### File [$1] Start ####"
 	cat $1
 	echo "#### File [$1] End   ####"
 	echo
 }
 #ShowFile () {
 #	echo $1
 #	echo "#### $1 ####" >> $WORK_FILE
 #	ls -l $1 >> $WORK_FILE
 #	cat $1 >> $WORK_FILE
 #	echo "" >> $WORK_FILE
 #}
 
 ExecCmd() {
 	echo "#### Command [$1] Start ####"
 	bash -c "$1"
 	echo "#### Command [$1] End   ####"
 	echo
 }
 #ExecCmd() {
 #	echo $1
 #	echo "#### $1 ####" >> $WORK_FILE
 #	$1 >> $WORK_FILE
 #	bash -c "$1" >> $WORK_FILE
 #	echo "" >> $WORK_FILE
 #}
 
 #if [ $# != 1 ];then
 #echo "Usage:`basename $0` BKUP_DIR"
 #exit
 #fi
 
 exec 2>&1
 
 export LANG=C
 #NOW=`date +%Y%m%d%H%M`
 #WORK_DIR=$1"/"$NOW"/"
 #WORK_FILE=$WORK_DIR"/"result.txt
 CMD=""
 TMP=""
 
 #if GetYN "mkdir $WORK_DIR OK?" ;then
 #:
 #else
 #exit
 #fi
 
 #mkdir $WORK_DIR
 #if [ $? != 0 ];then
 #echo "mkdir Error!!"
 #exit
 #fi
 
 echo "#### Get Information Start at `date` ####"
 echo
 echo "######################"
 echo "#### File Section ####"
 echo "######################"
 echo
 ShowFile /root/anaconda-ks.cfg
 ShowFile /etc/hosts
 ShowFile /etc/ld.so.conf
 ShowFile /lib/modules/`uname -r`/modules.dep
 ShowFile /etc/sysconfig/network
 ShowFile /etc/resolv.conf
 ShowFile /etc/fstab
 ShowFile /proc/cpuinfo
 ShowFile /proc/meminfo
 ShowFile /etc/sysctl.conf
 ShowFile /etc/passwd
 ShowFile /etc/group
 if [ -f /etc/modprobe.conf ];then
 	ShowFile /etc/modprobe.conf
 fi
 if [ -f /etc/X11/xorg.conf ];then
 	ShowFile /etc/X11/xorg.conf
 fi
 if [ -f /etc/modules.conf ];then
 	ShowFile /etc/modules.conf
 fi
 if [ -f /etc/ntp.conf ];then
 	ShowFile /etc/ntp.conf
 fi
 for i in /etc/sysconfig/network-scripts/ifcfg-* ; do
 	if [ -f $i ];then
 		ShowFile $i
 	fi
 done
 for i in /etc/*-release ; do
 	if [ -f $i ];then
 		ShowFile $i
 	fi
 done
 for i in /etc/X11/XF86Config* ; do
 	if [ -f $i ];then
 		ShowFile $i
 	fi
 done
 for i in /var/log/messages* ; do
 	if [ -f $i ];then
 		ShowFile $i
 	fi
 done
 for i in /var/spool/cron/* ; do
 	if [ -f $i ];then
 		ShowFile $i
 	fi
 done
 	
 
 echo "#########################"
 echo "#### Command Section ####"
 echo "#########################"
 echo
 #echo "#### Get Information Start at `date`" >> $WORK_FILE
 #echo "" >> $WORK_FILE
 
 CMD="chkconfig --list"
 ExecCmd "$CMD"
 
 CMD="crontab -l"
 ExecCmd "$CMD"
 
 CMD="date"
 ExecCmd "$CMD"
 
 CMD="df -k"
 ExecCmd "$CMD"
 
 CMD="dmesg"
 ExecCmd "$CMD"
 
 CMD="dmidecode"
 ExecCmd "$CMD"
 
 CMD="du -k /"
 #ExecCmd "$CMD"
 
 CMD="env"
 ExecCmd "$CMD"
 
 ifconfig |grep eth|cut -d" " -f 1|
 while read LINE
 do
 CMD="ethtool $LINE"
 ExecCmd "$CMD"
 done
 
 CMD="fdisk -l"
 ExecCmd "$CMD"
 
 CMD="free"
 ExecCmd "$CMD"
 
 CMD="hostname"
 ExecCmd "$CMD"
 
 CMD="hwclock -r"
 ExecCmd "$CMD"
 
 CMD="ifconfig -a"
 ExecCmd "$CMD"
 
 CMD="ipcs -al"
 ExecCmd "$CMD"
 
 CMD="ipcs -au"
 ExecCmd "$CMD"
 
 CMD="iptables -L"
 ExecCmd "$CMD"
 
 CMD="last"
 ExecCmd "$CMD"
 
 CMD="lastlog"
 ExecCmd "$CMD"
 
 CMD="ls -alR /"
 #ExecCmd "$CMD"
 #ls -alR / > ${WORK_DIR}ls-alR.txt
 
 CMD="lsmod"
 ExecCmd "$CMD"
 
 CMD="lspci"
 ExecCmd "$CMD"
 
 CMD="lspci -nv"
 ExecCmd "$CMD"
 
 CMD="lspci -v"
 ExecCmd "$CMD"
 
 CMD="lspci -vv"
 ExecCmd "$CMD"
 
 CMD="lspci -vvv"
 ExecCmd "$CMD"
 
 CMD="mount"
 ExecCmd "$CMD"
 
 CMD="netstat -a"
 ExecCmd "$CMD"
 
 CMD="netstat -an"
 ExecCmd "$CMD"
 
 CMD="netstat -ap"
 ExecCmd "$CMD"
 
 CMD="netstat -r"
 ExecCmd "$CMD"
 
 CMD="ntpq -p"
 ExecCmd "$CMD"
 
 CMD="ps auxww"
 ExecCmd "$CMD"
 
 CMD="ps alxww"
 ExecCmd "$CMD"
 
 CMD="route -n"
 ExecCmd "$CMD"
 
 CMD="rpm -qa | sort"
 ExecCmd "$CMD"
 
 CMD="rpm -qai"
 ExecCmd "$CMD"
 #rpm -qai > ${WORK_DIR}rpm-qai.txt
 
 CMD="rpm -qa --qf \"%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\\n\" | sort"
 ExecCmd "$CMD"
 #rpm -qa --qf \"%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\\n\" | sort > ${WORK_DIR}rpm-customform.txt
 
 #CMD="rpm -Va"
 #ExecCmd "$CMD"
 
 for i in /var/log/sa/sa?? ; do
 	if [ -f $i ];then
 #		cp -p $i $WORK_DIR
 		CMD="sar -A -f $i"
 		ExecCmd "$CMD"
 	fi
 done
 
 CMD="service --status-all"
 #ExecCmd "$CMD"
 
 CMD="set"
 ExecCmd "$CMD"
 
 CMD="swapon -s"
 ExecCmd "$CMD"
 
 CMD="sysctl -a"
 ExecCmd "$CMD"
 
 CMD="ulimit -a"
 ExecCmd "$CMD"
 
 CMD="uname -a"
 ExecCmd "$CMD"
 
 CMD="uptime"
 ExecCmd "$CMD"
 
 CMD="vmstat"
 ExecCmd "$CMD"
 
 CMD="w"
 ExecCmd "$CMD"
 
 
 #echo "#### Additional Section ####"
 
 # Make /etc archive ?
 #TMP=${WORK_DIR}etc_archive.tar.gz
 #if GetYN "make $TMP OK?" ;then
 #tar czvf $TMP /etc
 #fi
 
 # Make /var/log archive ?
 #TMP=${WORK_DIR}var-log_archive.tar.gz
 #if GetYN "make $TMP OK?" ;then
 #tar czvf $TMP /var/log
 #fi
 
 #TMP=$1"/"$NOW".tar"
 #if GetYN "make $TMP".bz2" OK?" ;then
 #tar cvf $TMP $WORK_DIR
 #bzip2 -9 $TMP
 #fi
 
 #TMP=$1"/"$NOW".tar.gz"
 #if GetYN "make $TMP OK?" ;then
 #tar czvf $TMP $WORK_DIR
 #fi
 
 exit