# Author: The Adventures of Tintin (Jacob)
# This script uses the Guestmount tool to mount the virtual machine's disk system to a real-world file system
# Centos7.2 Install libguestfs-tools-c to get Guestmount tools
# The virtual machine can start or not start without affecting the use of the script
# When you mount a virtual machine disk file to a file system, you can directly read the data in the NIC configuration file in the disk file the script uses the Guestmount tool to mount the virtual machine's disk system to a real-world file system
#!/bin/bash#author: Tintin (Jacob) #该脚本使用guestmount工具, you can mount a virtual machine's disk system to a real-world file system # Centos7.2 install libguestfs-tools-c can get Guestmount tool # Virtual machine can be started or not boot does not affect the use of the script # after the virtual machine disk files are mounted to the file system, You can directly read the data in the NIC configuration file in the disk file clearmountpoint= "/media/virtimage" [ ! -d $mountpoint]&& mkdir $mountpointread -p "Enter the virtual machine name:" nameecho "Please later ..." #如果有设备挂载到该挂载点 umount uninstall if Mount | grep -q "$mountpoint" ;then umount $ mountpointfi# read-only way, mount the virtual machine's disk file to a specific directory, here is the/media/virtimage directory guestmount -r -d $name -i$ Mountpointechoecho "--------------------------------------------" echo -e "\033[32m$name the list of network cards in the virtual machine is as follows: \ 033[0m "dev=$ (ls /media/virtimage/etc/sysconfig/network-scripts/ifcfg-*|awk -f" [/-] " ' {print $9} ') echo $devecho "--------------------------------------------" echoechoecho "++++++++++++++++ +++++++++++++++++++++++++++ "echo -e " \033[32m network card IP address information is as follows: \033[0m "FOR I&Nbsp;in $devdo echo -n "$i:" grep -q "ipaddr"/media/virtimage/etc/sysconfig/network-scripts/ifcfg-$i | | echo "IP Address Not Configured" awk -F= '/ipaddr/{print $2} ' /media/virtimage/etc/sysconfig/network-scripts/ifcfg-$idoneecho "++++++++++++++++++++++++++++++++++++++++ +++"
This article is from the "Ding Ding Adventures" blog, please be sure to keep this source http://manual.blog.51cto.com/3300438/1961346
Shell script: View network card information in a KVM virtual machine (no need to go into the boot or virtual machine)