您现在的位置是:首页 > 文章详情

通过shell脚本检测MySQL服务信息

日期:2018-10-06点击:324
通过shell脚本检测MySQL服务信息

今天改了一版脚本,对于MySQL的基本信息的获取有了一个相对比较清晰的收集方式。

我简单解释下脚本。

整体是分为两部分

第一部分是通过系统层面来解析MySQL的基本信息,方式是通过ps -ef|grep mysql得到的信息来解析。

第二部分是通过登录MySQL得到的信息,基本信息包括server_id,log_bin等。

脚本内容如下:

ps -ef|grep mysql |grep -w mysqld|grep -v grep |awk -F'--' '{for (i=2;i<=NF;i++) {printf $i" "}printf " "}' > info_from_sys.tmp

function get_info_from_sys()

{

while read line

do

array=$line

port_str='port='

socket_str='socket='

for arr_tmp in ${array[*]}; do

if [[ $arr_tmp =~ $port_str ]];then

port_tmp=`echo $arr_tmp|sed 's/port=//g'`

fi

if [[ $arr_tmp =~ $socket_str ]];then

socket_tmp=`echo $arr_tmp|sed 's/socket=//g'`

fi

done

if [ -z "$port_tmp" ];then

port_tmp=3306

fi

echo $port_tmp $socket_tmp >> info_from_sys.lst

done < info_from_sys.tmp

}

function get_info_from_db()

{

while read line

do

port=`echo $line|awk '{print $1}'`

#echo $port

/usr/local/mysql/bin/mysql -udba_admin -p$dec_passwd -h127.0.0.1 -P${port} -N -e "select @@port,@@log_bin,@@innodb_buffer_pool_size,@@gtid_mode,@@datadir,@@character_set_server,@@server_id,version();" >> info_from_db.lst

# echo $port_tmp $socket_tmp

done < info_from_sys.lst

}

function decrypt_passwd

{

tmp_passwd=$1

dec_passwd=`echo $tmp_passwd|base64 -d`

}

##MAIN

get_info_from_sys

sec_password='RHB6TEST1d1c5TTEzZGIwSgo=' --这个是数据库密码的base64加密串,可以根据需求来定制

dec_passwd=''

decrypt_passwd $sec_password

get_info_from_db

sort info_from_db.lst > info_from_db.tmp

sort info_from_sys.lst > info_from_sys.tmp

rm info_from_db.lst info_from_sys.lst

join -j 1 info_from_sys.tmp info_from_db.tmp

最后送波福利。现在加群即可获取Java工程化、高性能及分布式、高性能、高架构。性能调优、Spring,MyBatis,Netty源码分析和大数据等多个知识点高级进阶干货的直播免费学习权限及领取相关资料,群号:835638062 点击链接加入群聊【Java高级架构】:https://jq.qq.com/?_wv=1027&k=5S3kL3v

原文链接:https://yq.aliyun.com/articles/647549
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章