Wednesday, October 7, 2009

Save VM State During Logout

I run multiple VM's using VirtualBox on my laptop.  Few time I forgot to shutdown the VM's prior to logging off, which caused me to loose my work.  So, I decided to write a little script to save the state prior to logoff.

Add the following to your ~/.bash_logout

for vm in `/usr/bin/VBoxManage list runningvms | grep -E "^\"" | awk -F "\"" '{print $2}'`;
   /usr/bin/logger -p -t VirtualBox "Saving state: $vm"
   /usr/bin/VBoxManage controlvm $vm savestate | grep % | logger -p -t VirtualBox

Sample /var/log/messages output:

Oct 7 00:43:46 moonshine VirtualBox: Saving state: lamp32
Oct 7 00:43:48 moonshine VirtualBox: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%


No comments:

Post a Comment