#!/bin/bash # $Id$ set -e # store cfg file names of automaticly suspended vms in this file, so we # can auto resume on the next start. STATE=/var/run/vmware.suspended; # this function suspends running vms. function stop { running=""; for vm in `vmware-cmd -l`; do state=`vmware-cmd "$vm" getstate | grep "on"`; if [[ ! -z "$state" ]]; then running=`echo -e "$running\n$vm"`; echo "Suspending vm: $vm"; vmware-cmd "$vm" suspend; fi done echo "$running" > "$STATE"; } # resume suspended vms. function start { if [[ -f "$STATE" ]]; then for vm in `cat "$STATE"`; do echo "Resuming vm: $vm"; vmware-cmd "$vm" start; done rm "$STATE"; fi } case "$1" in start) start;; stop) stop;; esac exit 0;