shownotes-w3m-rice/virtualboxcli_vbx.md
2016-12-17 21:24:37 -08:00

5.1 KiB

Virtualbox CLI Functions

couple of functions i created to spin up and shutdown virtualbox virtual machines (vm) because is faster for me

  • tutorial video: Link
  • offical website: Link

install requirements

virtualbox
rdesktop

vm requirements: enable remote desktop on each vm

configuration

vim ~/.zshrc or vim ~/.bashrc


# Reset
Color_Off='\e[0m'       # Text Reset

# Regular Colors
Black='\e[0;30m'        # Black
Red='\e[0;31m'          # Red
Green='\e[0;32m'        # Green
Yellow='\e[0;33m'       # Yellow
Blue='\e[0;34m'         # Blue
Purple='\e[0;35m'       # Purple
Cyan='\e[0;36m'         # Cyan
White='\e[0;37m'        # White

vbx-list() {
  echo "===Available VM==="
  vboxmanage list vms
  echo "\n===Running VM====="
  vboxmanage list runningvms
}

vbx-start() {
  # Set to endless loop
  while true
  do
    # Set the prompt for the select command
    PS3="Type a number to select or 'Ctrl+C' to quit: "

    # Create a list to display on menu
    IFS=$'\n'
    fileList=($(vboxmanage list vms | cut -d '{' -f1 | sed 's/ *$//'))
    unset IFS

    # Show a menu and ask for input. If the user entered a valid choice then execute command
    select fileName in $fileList; do
      if [ -n "$fileName" ]; then
        # remove quotes from filename
        vm_name=($(echo "${fileName}" | sed 's:\"::g' ))
        vboxmanage startvm "$vm_name" --type headless
        echo -e "${Green} $vm_name Has Been Started ${Color_Off}"
      fi
      break
    done
  done
}

vbx-quit() {
  # Set to endless loop
  while true
  do
    # Set the prompt for the select command
    PS3="Type a number to select or 'Ctrl+C' to quit: "

    # Create a list to display on menu
    IFS=$'\n'
    fileList=($(vboxmanage list runningvms | cut -d '{' -f1 | sed 's/ *$//'))
    unset IFS

    # Show a menu and ask for input. If the user entered a valid choice then execute command
    select fileName in $fileList; do
      if [ -n "$fileName" ]; then
        # remove quotes from filename
        vm_name=($(echo "${fileName}" | sed 's:\"::g' ))
        vboxmanage controlvm "$vm_name" acpipowerbutton
        echo -e "${Yellow} $vm_name Is Shutting Down ${Color_Off}"
      fi
      break
    done
  done
}

vbx-forcequit() {
  # Set to endless loop
  while true
  do
    # Set the prompt for the select command
    PS3="Type a number to select or 'Ctrl+C' to quit: "

    # Create a list to display on menu
    IFS=$'\n'
    fileList=($(vboxmanage list runningvms | cut -d '{' -f1 | sed 's/ *$//'))
    unset IFS

    # Show a menu and ask for input. If the user entered a valid choice then execute command
    select fileName in $fileList; do
      if [ -n "$fileName" ]; then
        # remove quotes from filename
        vm_name=($(echo "${fileName}" | sed 's:\"::g' ))
        vboxmanage controlvm "$vm_name" poweroff
        echo -e "${Red} $vm_name Power Cable Has Been Pulled ${Color_Off}"
      fi
      break
    done
  done
}

rdesktop-winxp() {
  ipaddr=192.168.1.150
  port=3389
  username=gotbletu
  resolution=1920x1020
  echo "${Yellow}>>>Check if remote computer is alive at $ipaddr:$port ${Color_Off}"
    until nc -vzw 2 "$ipaddr" "$port"; do sleep 2; done
  echo "${Green}>>>Connecting to remote computer${Color_Off}"
    rdesktop -u "$username" -g "$resolution" "$ipaddr":"$port" -r sound:local
}

rdesktop-fedoramate64() {
  ipaddr=192.168.1.52
  port=3389
  username=gotbletu
  resolution=1920x1020
  echo "${Yellow}>>>Check if remote computer is alive at $ipaddr:$port ${Color_Off}"
    until nc -vzw 2 "$ipaddr" "$port"; do sleep 2; done
  echo "${Green}>>>Connecting to remote computer${Color_Off}"
    rdesktop -u "$username" -g "$resolution" "$ipaddr":"$port" -r sound:local
}

references

contact

             _   _     _      _         
  __ _  ___ | |_| |__ | | ___| |_ _   _ 
 / _` |/ _ \| __| '_ \| |/ _ \ __| | | |
| (_| | (_) | |_| |_) | |  __/ |_| |_| |
 \__, |\___/ \__|_.__/|_|\___|\__|\__,_|
 |___/