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

你可能感兴趣的:(jenkins,mysql)