Skip to content

Instantly share code, notes, and snippets.

@un33k
Created July 30, 2012 01:43
Show Gist options
  • Save un33k/3203224 to your computer and use it in GitHub Desktop.
Save un33k/3203224 to your computer and use it in GitHub Desktop.
Run Fusion 3.x OR 4.x in headless mode
# Start and stop headless VMs
# Val Neekman @ Neekware Inc.
# [email protected]
# You need to fix this to point to the right directory on your MAC
VMHOME="${HOME}/Documents/VMs"
if [ -z $1 ]
then echo "Usage: vm stop|start|stopall"
exit 1
fi
VMS=`find "${VMHOME}" -depth 1 -name "*.vmwarevm"`
# Locate the vmrun
VMRUN=''
VMRUN_3="/Library/Application Support/VMware Fusion/vmrun"
VMRUN_4="/Applications/VMware Fusion.app/Contents/Library/vmrun"
if [ -f "$VMRUN_4" ];
then
VMRUN=$VMRUN_4
else
if [ -f "$VMRUN_3" ];
then
VMRUN = $VMRUN_3
else
echo "Unable to locate vmrun"
exit 0
fi
fi
# Allow spaces in file dir/name
ORIG_IFS=${IFS}; IFS="
"
# stop all
if [ "$1" == "stopall" ]; then
# Loop through and shutdown all VMs
for opt in $VMS ; do
RUNNING=`ls $opt | grep "mem.lck" | wc -l | sed 's/ //g'`
if [ "$RUNNING" -gt 0 ]; then
# run file
`"${VMRUN}" stop "${opt}"`
# repair IFS
IFS=${ORIG_IFS}
fi
done
fi
# choose to stop one
if [ "$1" == "stop" ]; then
# Loop through and shutdown all VMs
select opt in $VMS ; do
RUNNING=`ls $opt | grep "mem.lck" | wc -l | sed 's/ //g'`
if [ "$RUNNING" -gt 0 ]; then
# run file
`"${VMRUN}" stop "${opt}"`
# repair IFS
IFS=${ORIG_IFS}
exit 0
fi
done
fi
# choose to start one # a non windows
if [ "$1" == "start" ]; then
select opt in $VMS ; do
RUNNING=`ls $opt | grep "Applications" | wc -l | sed 's/ //g'`
if [ "$RUNNING" -gt 0 ]; then
# run file
echo "Windows not supported"
exit 0
else
# run file
`"${VMRUN}" start "${opt}" nogui`
# repair IFS
IFS=${ORIG_IFS}
exit 0
fi
done
fi
IFS=${ORIG_IFS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment