流程如下:getpass.py 后面跟实例id 可以获取到数据库连接信息 ,比如1027实例 获取到的信息:mysql -uc2n -p"xmjbmns" -h10.126.1.2 -P3306,但是在shell里
sh -x mysql_check.sh 结果如下,不明白为啥在密码哪里多了一对单引号 '-p"xmjbmns"' 导致无法连接数据库,请问如何去掉- #!/bin/bash
-
- instance="1027"
- Date=`date +'%Y-%m-%d %H:%M:%S'`
- mail_log=/tmp/mysql.log
-
- slave=`python /opt/monitorAPI/model/getpass.py $instance |grep -E -A 1 'Slave:'|grep mysql`
- declare -a slave_status
- slave_status=($($slave -e "show slave status\G"|grep Running |awk '{print $2}'))
-
- if [ "${slave_status[0]}" = "Yes" -a "${slave_status[1]}" = "Yes" ]
- then
- echo "OK slave is running"
- exit 0
- else
- error=1
- echo ""$Date" slave mysql "$i" error" >>"$mail_log"
- fi
复制代码 [root@zz-001 ~]# sh -x mysql_check.sh
+ instance=1023
++ date '+%Y-%m-%d %H:%M:%S'
+ Date='2020-04-07 15:53:42'
+ mail_log=/tmp/mysql.log
++ python /opt/monitorAPI/model/getpass.py 1023
++ grep -E -A 1 Slave:
++ grep mysql
+ slave='mysql -uc2n -p"xmjbmns" -h10.126.1.2 -P3306'
+ echo mysql -uc2n '-p"xmjbmns"' -h10.126.1.2 -P3306
mysql -uc2n -p"xmjbmns" -h10.126.1.2 -P3306
+ declare -a slave_status
+ slave_status=($($slave -e "show slave status\G"|grep Running |awk '{print $2}'))
++ mysql -uc2n '-p"xmjbmns"' -h10.126.1.2 -P3306 -e 'show slave status\G'
++ grep Running
++ awk '{print $2}'
ERROR 1045 (28000): Access denied for user 'c2n'@'10.126.1.2' (using password: YES) |