하드웨어 정보 수집 Script
스크립트 작성 목적
UXEN3 설치 후 보고서 작성 및 UXEN 설치 점검을 효율적으로 하기 위해서 개인적인 목적으로 작성했습니다.
스크립트 설명
UXEN 설치 후 Physical Machine(PM)의 시스템 정보를 수집하는 쉘 스크립트입니다.
프로그램 실행 결과
수집한 정보는 /root/PM에 저장합니다.
# ./get_pm_info.sh /root/PM
수집한 정보는 /root/PM의 하위 디렉토리에 생성됩니다.
# tree /root/PM
/root/PM
├── hw_info
│ ├── cpuinfo-jennings.txt
│ ├── dmidecode-jennings.txt
│ ├── dmidecode_bios-jennings.txt
│ ├── dmidecode_memory-jennings.txt
│ ├── dmidecode_system-jennings.txt
│ ├── lshw-jennings.txt
│ ├── meminfo-jennings.txt
│ └── raid-jennings.txt
├── network_info
│ ├── brctlshow-jennings.txt
│ ├── ifconfig-jennings.txt
│ ├── interfaces-jennings.txt
│ └── route-jennings.txt
├── partitions_and_disk_info
│ ├── df_Th-jennings.txt
│ ├── fdisk_l-jennings.txt
│ └── parted_l-jennings.txt
└── sys_status_and_settings_info
├── dmesg-jennings.txt
├── dpkg_l-jennings.txt
├── dstat-jennings.txt
├── free_h-jennings.txt
├── fstab-jennings.txt
├── grub-jennings.txt
├── kern.log-jennings.txt
├── lsmod-jennings.txt
├── uname_a-jennings.txt
└── xl_info-jennings.txt
예를들어 /root/PM/sys_status_and_settings_info/xl_info-jennings.txt의 파일 내용은 아래와 같습니다.
# cat /root/PM/sys_status_and_settings_info/xl_info-jennings.txt
host : jennings
release : 3.16.0-4-amd64
version : #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02)
machine : x86_64
nr_cpus : 4
max_cpu_id : 3
nr_nodes : 1
cores_per_socket : 4
threads_per_core : 1
cpu_mhz : 2664
hw_caps : bfebfbff:20100800:00000000:00000900:0408e3fd:00000000:00000001:00000000
virt_caps : hvm
total_memory : 8191
free_memory : 6815
sharing_freed_memory : 0
sharing_used_memory : 0
outstanding_claims : 0
free_cpus : 0
xen_major : 4
xen_minor : 4
xen_extra : .1
xen_version : 4.4.1
xen_caps : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64
xen_scheduler : credit
xen_pagesize : 4096
platform_params : virt_start=0xffff800000000000
xen_changeset :
xen_commandline : placeholder dom0_max_vcpus=4 dom0_vcpus_pin crashkernel=256M@64M dom0_mem=1G,max:1G
cc_compiler : gcc (Debian 4.9.2-10) 4.9.2
cc_compile_by : carnil
cc_compile_domain : debian.org
cc_compile_date : Wed Apr 20 13:17:38 UTC 2016
xend_config_format : 4
프로그램 소스
#!/bin/bash
#Hyun-gwan Seo
HOSTNAME=`hostname`
BASE="$1"
HW_INFO_PATH="$BASE/hw_info"
PARTITIONS_DISK_PATH="$BASE/partitions_and_disk_info"
NET_INFO_PATH="$BASE/network_info"
SYS_STATUS_AND_SETTINGS_PATH="$BASE/sys_status_and_settings_info"
function init()
{
if [ ! -d $BASE ]; then
mkdir -p $BASE
fi
if [ ! -d $HW_INFO_PATH ]; then
mkdir -p $HW_INFO_PATH
fi
if [ ! -d $PARTITIONS_DISK_PATH ]; then
mkdir -p $PARTITIONS_DISK_PATH
fi
if [ ! -d $NET_INFO_PATH ]; then
mkdir -p $NET_INFO_PATH
fi
if [ ! -d $SYS_STATUS_AND_SETTINGS_PATH ]; then
mkdir -p $SYS_STATUS_AND_SETTINGS_PATH
fi
}
#HW 정보를 수집합니다.
function get_hw_info()
{
dmidecode > $HW_INFO_PATH/dmidecode-$HOSTNAME.txt
dmidecode -t memory > $HW_INFO_PATH/dmidecode_memory-$HOSTNAME.txt
dmidecode -t bios > $HW_INFO_PATH/dmidecode_bios-$HOSTNAME.txt
dmidecode -t system > $HW_INFO_PATH/dmidecode_system-$HOSTNAME.txt
lspci | grep -i raid > $HW_INFO_PATH/raid-$HOSTNAME.txt
lshw > $HW_INFO_PATH/lshw-$HOSTNAME.txt
cat /proc/cpuinfo > $HW_INFO_PATH/cpuinfo-$HOSTNAME.txt
cat /proc/meminfo > $HW_INFO_PATH/meminfo-$HOSTNAME.txt
}
#파티션과 디스크 정보를 수집합니다.
function partitions_and_disk_info()
{
echo "Ignore" | parted -l > $PARTITIONS_DISK_PATH/parted_l-$HOSTNAME.txt
df -Th > $PARTITIONS_DISK_PATH/df_Th-$HOSTNAME.txt
fdisk -l > $PARTITIONS_DISK_PATH/fdisk_l-$HOSTNAME.txt
}
#네트워크 정보를 수집합니다.
function get_network_info()
{
cp /etc/network/interfaces $NET_INFO_PATH/interfaces-$HOSTNAME.txt
brctl show > $NET_INFO_PATH/brctlshow-$HOSTNAME.txt
ifconfig > $NET_INFO_PATH/ifconfig-$HOSTNAME.txt
route > $NET_INFO_PATH/route-$HOSTNAME.txt
}
#시스템 상태 및 설정 값을 수집합니다.
function get_system_status_and_settings()
{
dmesg > $SYS_STATUS_AND_SETTINGS_PATH/dmesg-$HOSTNAME.txt
cat /var/log/kern.log > $SYS_STATUS_AND_SETTINGS_PATH/kern.log-$HOSTNAME.txt
dpkg -l > $SYS_STATUS_AND_SETTINGS_PATH/dpkg_l-$HOSTNAME.txt
lsmod > $SYS_STATUS_AND_SETTINGS_PATH/lsmod-$HOSTNAME.txt
uname -a > $SYS_STATUS_AND_SETTINGS_PATH/uname_a-$HOSTNAME.txt
cat /etc/fstab > $SYS_STATUS_AND_SETTINGS_PATH/fstab-$HOSTNAME.txt
cat /etc/default/grub > $SYS_STATUS_AND_SETTINGS_PATH/grub-$HOSTNAME.txt
dstat 1 10 > $SYS_STATUS_AND_SETTINGS_PATH/dstat-$HOSTNAME.txt
xl info > $SYS_STATUS_AND_SETTINGS_PATH/xl_info-$HOSTNAME.txt
xl list > $SYS_STATUS_AND_SETTINGS_PATH/xl_list-$HOSTNAME.txt
free -h > $SYS_STATUS_AND_SETTINGS_PATH/free_h-$HOSTNAME.txt
}
if [ 0 -eq $# ]; then
echo "Usage: $0 LOG_DIR"
exit
fi
init
get_hw_info
partitions_and_disk_info
get_network_info
get_system_status_and_settings