Skip to content

Instantly share code, notes, and snippets.

@helix84
Created October 7, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helix84/4af0cd5d05b5949a30155c604fab0658 to your computer and use it in GitHub Desktop.
Save helix84/4af0cd5d05b5949a30155c604fab0658 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Author: Ivan Masar, 2015
# License: public domain
#
# list running VMs by name
# for each VM print selected fields from vminfo
# format it into a table (using "column")
print_header=1
for i in `VBoxManage list vms | awk '{print $NF}' | sed 's/"//g'`; do
if [ "$print_header" -eq "1" ]; then
echo "VRDE\tRAM\tname\tstatus"
print_header=0
fi
vminfo=`VBoxManage showvminfo $i`
state_full=`echo "$vminfo" | grep "^State:" | awk '{$1=""; printf "%s\t", substr($0,2)}'` # all fields except the first
state_print="$state_full\t"
state_start=`echo $state_full | awk '{printf "%s", substr($0,1,5)}'`
if [ "$state_start" = "runni" ]; then
state_print="\033[32m$state_full\t\033[0m" # ANSI green
elif [ "$state_start" = "saved" ]; then
state_print="\033[36m$state_full\t\033[0m" # ANSI cyan
elif [ "$state_start" = "power" ]; then
state_print="\033[33m$state_full\t\033[0m" # ANSI yellow
elif [ "$state_start" = "abort" ]; then
state_print="\033[31m$state_full\t\033[0m" # ANSI red
fi
echo "$vminfo" | grep "^VRDE port:" | awk '{printf "%s\t", $3} END { if (!NR) printf "N/A\t" }'
echo "$vminfo" | grep "^Memory size:" | awk '{printf "%s\t", $3} END { if (!NR) printf "N/A\t" }'
echo "$vminfo" | grep "^Name: " | awk '{$1=""; printf "%s\t", substr($0,2)}' # all fields except the first
printf "$state_print"
printf "\n"
done | column -s "`printf '\t'`" -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment