首页 > 数据库技术 > 详细

收集服务器信息脚本并写入数据库

时间:2019-10-28 00:31:53      阅读:101      评论:0      收藏:0      [点我收藏+]
#!/bin/bash
# **********************************************************
# * Author        : quanzhiqiang
# * Email         : 13145710069@163.com
# * Create time   : 2019-10-27 21:34
# * Filename      : server_info.sh
# * Description   : 
# *********************************************************
echo -e "\033[34m \033[1m"
cat <<EOF
----------------------------------------------------------
-----------------server system information collect-----------
-------------------------------------------------------------
EOF

######################################统计服务器的基本信息###########################################
#function sum_info(){
    all_ip_info=`ifconfig |grep "Bcast"|awk  {print $2} |cut -d: -f 2 |tr \n \t`
    cpu_info_brand=`cat /proc/cpuinfo |grep "model name" |awk -F: {print $2}|sed s/^ //g|cut -d " " -f 1,3,4,6`
    cpu_heshu=`cat /proc/cpuinfo |grep "^physical" |sort|uniq -c |tr -s   |tail -1 |cut -d   -f 2`
    cpu_geshu=`cat /proc/cpuinfo |grep "^physical" |sort|uniq -c |wc -l`
    disk_info=`fdisk -l |grep "Disk" |grep -v "identifier" |awk {print $2 $3 $4} |sed s/,//g`
    mem_info=`free -m  |grep "Mem"|awk {print "Total_"$1,$2"M"}`
    load_info=`uptime |awk {print "Current Load:" $(NF-2) }|sed s/,//`
#    }
######################################输出服务器的基本信息#############################################
function print_info(){
    echo -e "\033[32m >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[1m"
    echo "ALL_IPADDR:    ${all_ip_info}"
    echo "CUP_BRAND:    ${cpu_info_brand}"
    echo "CPU_AUDITING:    ${cpu_heshu}"
    echo "CPU_NUMBER:    ${cpu_geshu}"
    echo "DISK_INFO:    ${disk_info}"
    echo "MEM_INFO:     ${mem_info}"
    echo "LOAD_INFO:    ${load_info}"
    echo -e "\033[0m"
    }
#####################################三个点的函数#############################################
function wait(){
    for ((i=0;i<3;i++))
    do
        echo -n "."
        sleep 1
    done
    }

#######################################数据库的写入#####################################
function write_db(){
    echo -e "\033[35m <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< \033[0m"
    echo -e "\033[35m Write this data to the databases? \033[0m"
    echo -e  "\033[35m Please input Y/N \033[0m" 
    read input
    if [ "$input" == "Y" ] ;then
        echo -e "\033[31m"
        echo -n "Begin to write"
        wait
        echo -e "\033[0m"
    ######write databases
    #mysql -u root -p 2004 -D test -e "insert into server_data values(‘‘,‘${all_ip_info}‘,‘*******************‘)"
        echo ""
    else
        echo -e "\033[31m"
        echo -n "Begin to exit"
        wait
        echo -e "\033[0m"
        exit
    fi
    }
#####################################调用###################################
print_info
write_db

 

收集服务器信息脚本并写入数据库

原文:https://www.cnblogs.com/betterquan/p/11749885.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!