Create a shell with a case statement (function is open, close, reset, display virtual machine)

Source: Internet
Author: User
Tags case statement

Create a shell with a case statement (function is open, close, reset, display virtual machine)

#!/bin/bash

Case "$" in

Start)/* When the keyword is start, execute the statement that opens the virtual machine

echo Start ...

Virsh Start $ &>/dev/null

;;

Poweroff)/* Executes a statement that forces the virtual machine to be closed when the keyword is Poweroff

Echo Poweroff ...

Virsh Destroy &>/dev/null

;;

View)/* Executes the statement that displays the virtual machine interface, when the keyword is view

Virt-viewer &>/dev/null &

;;

Reset)/* When the keyword is reset, perform a restart of the virtual machine

echo Reset ...

Echo Poweroff ...

Virsh Destroy $ &>/dev/null/* Forcibly shutting down virtual machine

Echo del $1.xml ...

Virsh undefine $ &>/dev/null/* Delete Front end

Echo Create Disk ...

Qemu-img create-f qcow2-b/var/lib/libvirt/images/$2.img/var/lib/libvirt/images/$2.img &>/dev/null /* Take a snapshot of the hard disk

Echo Create-$ VM ...

Virt-install \/* Create a virtual machine

--name

--ram 1000 \

--DISK/VAR/LIB/LIBVIRT/IMAGES/$2.IMG \/* Create a hard drive directory

--import &>/dev/null &/* Import graphical interface

ECHO Create $ successful!!!

;;

*)

echo "Error:please input Reset|view|start|poweroff after three"

Esac


Create a shell with a case statement (function is open, close, reset, display 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.