zoukankan      html  css  js  c++  java
  • Virtualbox开机启动,service命令管理

    #!/bin/bash
    #chkconfig:235 80 20
    #description:start or stop vbox
    #Author:AiYS~20180502
    #OS:RedHatEnterprise6.4,上传vbox至/etc/init.d/并赋权755,chkconfig --add vbox添加后可开机启动并用service命令管理


    . /etc/rc.d/init.d/functions
    . /etc/sysconfig/network

    VBoxManage list vms &>/dev/null
    [ $? -eq 0 ] && VBuuid=($(VBoxManage list vms | awk '{print $2}' | tr -d {})) || VBuuid=()
    function start {
    if [ ${#VBuuid[*]} -gt 0 ];then
      for vbstart in ${VBuuid[*]}
      do
        VBname=$(VBoxManage showvminfo ${vbstart} --machinereadable | egrep "name" | awk -F'"' '{print $2}')
        [ $(VBoxManage showvminfo ${vbstart} --machinereadable | egrep "VMState" | awk -F'"' '{print $2}')=running ] && echo -e "${VBname}正在运行!" || VBoxManage startvm ${vbstart} --type headless &>/dev/null
      done
    else
      echo -e "本机未安装VirtualBox!"
    fi
    }

    function stop {
    VBoxManage list runningvms &>/dev/null
    [ $? -eq 0 ] && VBrunning=($(VBoxManage list runningvms | awk '{print $2}' | tr -d {})) || VBrunning=()
    if [ ${#VBrunning[*]} -gt 0 ];then
      for vbstop in ${VBrunning[*]}
      do
        VBoxManage controlvm ${vbstop} acpipowerbutton && echo -e "关闭$(VBoxManage showvminfo ${vbstop} --machinereadable | egrep "name" | awk -F'"' '{print $2}')"
      done
    else
      echo "本机没有运行的VirtualBox!"
    fi
    }

    function status {
    if [ ${#VBuuid[*]} -gt 0 ];then
      for vbstate in ${VBuuid[*]}
      do
        name=$(VBoxManage showvminfo ${vbstate} --machinereadable | egrep "name" | awk -F'"' '{print $2}')
        state=$(VBoxManage showvminfo ${vbstate} --machinereadable | egrep "VMState" | awk -F'"' '{print $2}')
        echo -e "${name} ${state}"
      done
    else
      echo -e "本机未安装VirtualBox!"
    fi
    }

    case "$1" in
      start)
        start;;
      stop)
        stop;;
      status)
        status;;
      *)
        echo -e "Format error! eg:service $0 {start|stop|status}"
        exit 1;;
    esac

    ******开机启动虚拟机******

    在/etc/rc.local中增加:

    sh /etc/init.d/vbox start

  • 相关阅读:
    泛泰A870(高通APQ8064t 600 cpu) Mokee4.4.2(Android4.4) 图赏
    cocos2d-x 游戏优化方案
    IOS中用UIStoryBoard类初始化/跳转控制器
    PHPthinking邀请您一起赚Money
    天凉好个秋(连载九)
    图像处理之Canny边缘检測
    SAE+wordpress邮箱问题,WP MAIL STMP插件配置但无效解决的方法
    Codeforces Beta Round #25 (Div. 2)--A. IQ test
    eclipse4.2+安装modelgoon插件,该插件支持在eclipse直接依据java文件生产类图
    使用Volley缓存图片时,缓存无效的原因。
  • 原文地址:https://www.cnblogs.com/AiYS/p/8982264.html
Copyright © 2011-2022 走看看