KVM虚拟机获取所有IP(shell)

Shell

running_vms=`virsh list |grep running`
echo -ne "共有`echo "$running_vms"|wc -l`个虚拟机在运行.\n"
for i in `echo "$running_vms" | awk '{ print $2 }'`;do
    mac=`virsh dumpxml $i |grep "mac address"|sed "s/.*'\(.*\)'.*/\1/g"`
    ip=`arp -ne |grep "$mac" |awk '{printf $1}'`
    printf "%-30s %-30s\n" $i $ip
done

 

命令行

# Get {i} machine ip
virsh dumpxml win_ultimate_x64 | grep mac  查看mac
arp -a  查看对应mac的IP地址 

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 黑客帝国 设计师:白松林 返回首页