mysql authorization check

jenkins input $mysqllist

ip地址+端口+用户名+db库+dbaManager

jenkins command lines

# generate a result file
echo "" > returnResult.txt

for ip in $iplist
do
    ssh -o StrictHostKeyChecking=no root@$ip 'which mysql && echo "mysql命令已存在" || yum install -y mysql'

for mysql in $mysqllist
do
    returnResult=""
    mysqlip=`echo $mysql | awk -F+ '{print $1}'`
    mysqlport=`echo $mysql | awk -F+ '{print $2}'`
    mysqluser=`echo $mysql | awk -F+ '{print $3}'`
    mysqldb=`echo $mysql | awk -F+ '{print $4}'`
    mysqldba=`echo $mysql | awk -F+ '{print $5}'`
    result=`ssh -o StrictHostKeyChecking=no root@$ip "mysql -h $mysqlip -P $mysqlport -u $mysqluser $mysqldb 2>&1"` || a=1 
    count1=`echo $result | grep "not allowed" | wc -l` 
    count2=`echo $result | grep "Access denied" | wc -l`
    count3=`echo $result | grep "Can't connect" | wc -l`
    echo $count1
    echo $count2
    echo $count3
    [[ $count1 -eq 1 ]] && checkResult="[不允许访问][请开通权限]"
    [[ $count2 -eq 1 ]] && checkResult="[密码不正确][权限已开通]"
    [[ $count3 -eq 1 ]] && checkResult="[数据库异常]"
    returnResult="@$mysqldba From $ip TO $mysqluser@$mysqlip:$mysqlport/$mysqldb....$checkResult"
    echo
    echo
    echo $returnResult >> returnResult.txt
    #exit
done

done

cat returnResult.txt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值