#!/bin/bash
# set -x
list=(
# $1
10.56.216.xxx
10.56.216.xxx
10.56.31.xxx
10.56.31.xxx
10.56.31.xxx
10.56.31.xxx
10.56.31.xxx
)
# for i in ${list[*]}
# do
# vm_id_list=$(timeout 10 sshpass -p 'root@123' ssh -o StrictHostKeyChecking=no root@$i "virsh list | grep i-y| awk '{print \$2}'")
# sql=`mysql -h localhost -u root -p'root@123' -D ceshi -e "select ip from host_table where ip='$i'"`
# echo $vm_id_list
# done
#每个host检查函数
host_check(){
vm_id_list=$(timeout 3 sshpass -p 'root@123' ssh -o StrictHostKeyChecking=no root@$1 "virsh list | grep i-y| awk '{print \$2}'")
for id in $vm_id_list
do
sql=`mysql -h localhost -u root -p'root@123' -D ceshi -e "select vm_id from create_new_host where vm_id='$id'"`
echo $sql
jieguo=`echo $sql | cut -d ' ' -f 2`
#echo $jieguo
if [ -z $jieguo ]
then
echo $id '是非法机器需要删除'
else
echo ''
fi
done
}
for i in ${list[*]}
do
{
host_check $i
}&
done
wait
检测虚机是否是在测试数据库中 shell 脚本
最新推荐文章于 2024-08-15 01:26:58 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)