#!/bin/bash # # Search VM info by grep of showvm output # # e.g. To sum total memory of VMs: # ./080-search-vm-info.bash "Memory size"|grep "size:"| \ # cut -d":" -f2|sed 's/MB//'| \ # awk '{s+=$1} END {print s/1024 " GB"}' # # Run user check if [ "$UID" -eq 0 ] then echo "This script should NOT be run as root." exit 1 fi # # Source config file if [ ! -f ~/.vbconfig ]; then echo "Config File ~/.vbconfig not found!" echo "Run: set-folders to create .vbconfig" exit 1 fi . ~/.vbconfig # if [ $# -ne 1 ]; then echo "Usage for $0 : Search string required as argument" echo 'e.g.: 080-search-vm-info.bash "Memory size"' exit 1 fi # VM_SEARCH="$1" # VM_LIST=`VBoxManage list vms|sort|awk '{print $1}'` for VM in $VM_LIST do VM1="${VM//\"}" echo "Seraching for string '$VM_SEARCH' in VM '$VM1'" VBoxManage showvminfo "${VM1}" | grep --color=auto "${VM_SEARCH}" done # exit