#!/bin/sh
#auto get system info
#by zkg 2019-07-11
echo -e "\033[34m \033[1m"
cat << EOF
--------------请查看系统相关信息----------------
EOF
echo -e "\033[32m \033[0m"
#定义系统相关信息变量
IP_INFO=ifconfig|grep "Bcast"|tail -1|awk '{print $2}'|awk -F: '{print $2}'
SERV_INFO=hostname|tail -1
CPU_INFO1=cat /proc/cpuinfo |grep "model name"|awk -F: '{print $2}'|awk '{print $1,$2,$3,$4,$7}'|tail -1
CPU_INFO2=cat /proc/cpuinfo|grep "physical id"|wc -l
CPU_INFO="$CPU_INFO1 X $CPU_INFO2"
MEM_INFO=free -m|grep "Mem"|awk '{print "total",$2"M"}'
DISK_INFO=fdisk -l|grep "Disk"|grep -v "identifier"|grep -v "VolGroup"|awk -F, '{print $1}'|awk '{print $2,$3,$4}'
LOAD_INFO=uptime|awk -F, '{print $4$5,$6}'|awk -F: '{print $2}'|awk '{print "1分钟负载:",$1,"5分钟负载:",$2,"15分钟负载:",$3}'
MARK_INFO="HangZhou_AnHeng"
#输出系统相关信息
echo -e "\033[32m----------------------------------------------------\033[1m"
echo "IP_INFO:$IP_INFO"
echo "SERV_INFO:$SERV_INFO"
echo "CPU_INFO:$CPU_INFO"
echo "MEM_INFO:$MEM_INFO"
echo "DISK_INFO:$DISK_INFO"
echo "LOAD_INFO:$LOAD_INFO"
echo "MARK_INFO:$MARK_INFO"
echo -e "\033[32m----------------------------------------------------\033[0m"
#输出到excel表格中
echo -e "\033[32mYou want to write the data to the excel?[YES/Yes/yes/y/Y]or[NO/no/n/N]:\033[0m"
read ENSURE
if [ "$ENSURE" == "YES" -o "$ENSURE" == "Yes" -o "$ENSURE" == "yes" -o "$ENSURE" == "y" -o "$ENSURE" == "Y" ];then
echo "IP地址,主机名称,CPU信息,内存信息,磁盘信息,负载信息,所属单位" >> 31.111_system.csv
echo "$IP_INFO,$SERV_INFO,$CPU_INFO,$MEM_INFO,$DISK_INFO,$LOAD_INFO,$MARK_INFO" >> 31.111_system.csv
echo -e "\033[32mwrite the data to the excel successfully!\033[0m"
elif [ "$ENSURE" == "NO" -o "$ENSURE" == "no" -o "$ENSURE" == "n" -o "$ENSURE" == "N" ];then
exit 0
else
exit
fi