Skip to content

Instantly share code, notes, and snippets.

@vStone
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vStone/bfea500e6e01a291b002 to your computer and use it in GitHub Desktop.
Save vStone/bfea500e6e01a291b002 to your computer and use it in GitHub Desktop.
#!/bin/bash
( echo 'VM|Status|IP|Memory|OS';
for node in `lxc-ls -1`; do
tmpfile=`mktemp -t lxc-info-$node-XXXXXXX`;
lxc-info -n $node | sed 's@[ ]*:[ ]*@:@' > $tmpfile
status=$( cat $tmpfile | grep 'State:' | awk -F: '{print $2}' );
ip=""; mem=""; os=""; osver="";
if [ "$status" == "RUNNING" ]; then
ip=$( cat $tmpfile | grep 'IP:' | awk -F: '{print $2}' );
mem=$( cat $tmpfile | grep 'Memory use:' | awk -F: '{print $2}' );
lxc-attach -n $node -- facter > $tmpfile;
os=$( cat $tmpfile | grep 'operatingsystem =>' | awk '{print $3}');
osver=$( cat $tmpfile | grep 'operatingsystemrelease =>' | awk '{print $3}' );
fi;
echo "$node|$status|$ip|$mem|$os $osver";
rm $tmpfile
done;
) | column -t -s'|' -o ' | '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment