tips/shells/getinfo5

Last-modified: 2007-08-01 (水) 22:52:21
#!/bin/bash
# 2007.07.31 設定ファイルをcpからcatで表示に変更(ShowFile関数追加)
#            "exec 2>&1"追加
#            /etc,/var/logのアーカイブを作成する処理を追加
#            WORK_FILEに"1"を入力すれば標準出力に出力される??
#            dmidecode追加
#
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
	echo "#### $1 ####" >> $WORK_FILE
	ls -l $1 >> $WORK_FILE
	cat $1 >> $WORK_FILE
	echo "" >> $WORK_FILE
}
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 "#### Copy Section ####"
ShowFile /root/anaconda-ks.cfg
ShowFile /etc/hosts
ShowFile /etc/sysconfig/network-scripts/ifcfg-*
ShowFile /etc/ld.so.conf
ShowFile /lib/modules/`uname -r`/modules.dep
ShowFile /etc/sysconfig/network
ShowFile /etc/resolv.conf
ShowFile /etc/fstab
ShowFile /var/log/messages*
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/*-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/sa/sa?? ; do
	if [ -f $i ];then
		cp -p $i $WORK_DIR
	fi
done
echo "#### Command Section ####"
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 -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 auxw"
ExecCmd "$CMD"
CMD="ps alxw"
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"
#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