• 一个简单的vbox后台启动/停止/查看虚拟机的脚本


    脚本内容如下:

    #!/bin/bash
    
    cmd=$1
    vm=$2
    
    function info(){
        # 32 green
        ARGE=$1
        echo -e "\033[32mINFO: $ARGE\033[1m"
    }
    
    function warn(){
        ARGE=$1
        echo -e "\033[33mWARN: $ARGE\033[1m"
    }
    
    function error(){
        ARGE=$1
        echo -e "\033[31mERROR: $ARGE\033[1m"
    }
    
    function checkvms(){
        vmlist=$(/usr/bin/VBoxManage list vms|awk -F'"' '{print $2}'|xargs echo|sed 's/ /|/g')
        if [ "${vm}" == "" ];then
    		error "请输入vm!"
    		exit 1
        elif [[ ! $1 =~ $vmlist ]];then
    		error "$1 不存在"
            exit 1
        fi
    }
    
    if [[ ! ${cmd} =~ start|ls|lsrun|stop ]];then
    	warn "请参考如下命令使用:"
    	echo "vmctl [start|ls|lsrun|stop] vm"
    	exit 2
    fi
    
    
    case ${cmd} in
    start)
         checkvms ${vm}
         /usr/bin/VBoxManage startvm ${vm} --type headless
        ;;
    ls)
    	/usr/bin/VBoxManage list vms
        ;;
    lsrun)
    	/usr/bin/VBoxManage list runningvms
        ;;
    stop)
    	checkvms ${vm}
    	/usr/bin/VBoxManage controlvm ${vm} poweroff
        ;;
    esac
    

      

    转载请标明出处:http://www.cnblogs.com/duzhaoqi/
  • 相关阅读:
    Python字符串的切片
    Python字符串的劈分
    Python函数的参数
    接口幂等性
    Kafka 中的设计思想
    Stream特性
    API接口的安全设计验证:ticket,签名,时间戳
    linux命令
    Java注解和反射
    su 和 sudo
  • 原文地址:https://www.cnblogs.com/duzhaoqi/p/15777920.html
Copyright © 2020-2023  润新知