Created
September 3, 2015 15:10
-
-
Save helix84/d3e51cfbee673a92ece7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "name\tVRDE\tRAM\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 "^Name: " | awk '{$1=""; printf "%s\t", substr($0,2)}' # all fields except the first | |
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" }' | |
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