标签:执行 ast 系统信息 creat dso tail $2 config 信息
1、创建数据库表audit_system
(ID
int(11) NOT NULL AUTO_INCREMENT,IP_INFO
varchar(255) NOT NULL,SERV_INFO
varchar(255) NOT NULL,CPU_INFO
varchar(255) NOT NULL,MEM_INFO
varchar(255) NOT NULL,DISK_IFNO
varchar(255) NOT NULL,LOAD_INFO
varchar(255) NOT NULL,MARK_INFO
varchar(255) NOT NULL,ID
)2、执行脚本,脚本如下:
#!/bin/sh
#auto get system info
#by zkg 2019-07-11
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"
#输出到数据库表中
echo -e "\033[32mYou want to write the data to the Database?[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 "insert into audit_system values(‘‘,‘$IP_INFO‘,‘$SERV_INFO‘,‘$CPU_INFO‘,‘$MEM_INFO‘,‘$DISK_INFO‘,‘$LOAD_INFO‘,‘$MARK_INFO‘)"|mysql -usoc -psoc -Dsoc
echo -e "\033[32mwrite the data to the database successfully!\033[0m"
elif [ "$ENSURE" == "NO" -o "$ENSURE" == "no" -o "$ENSURE" == "n" -o "$ENSURE" == "N" ];then
exit 0
else
exit
fi
标签:执行 ast 系统信息 creat dso tail $2 config 信息
原文地址:https://blog.51cto.com/1009516/2425817