Shell script: View network card information in a KVM virtual machine (no need to go into the boot or virtual machine)

Source: Internet
Author: User

# 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.