Last active
August 29, 2015 14:18
-
-
Save tedwardd/22b3a7f5a58d916a481b to your computer and use it in GitHub Desktop.
vmrun_daemon
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/bash | |
export PATH=$PATH:"/Applications/VMware Fusion.app/Contents/Library" | |
vm="$2" | |
action="$1" | |
vm_path="/Users/user/vm-links" | |
case $1 in | |
start) | |
if [ -h "${vm_path}/${vm}" ]; then | |
vmrun start ${vm_path}/${vm} nogui >> /dev/null & | |
echo "${vm} started" | |
disown | |
echo $(pgrep -n "VMw") > ${vm_path}/${vm}.pid | |
else | |
echo "${vm} is not a valid vm name, exiting..." | |
exit 1 | |
fi | |
;; | |
stop) | |
if [ -h "${vm_path}/${vm}" ]; then | |
if [ -f ${vm_path}/${vm}.pid ]; then | |
PID=$(cat ${vm_path}/${vm}.pid); | |
echo "Stopping ${vm}..." | |
vmrun stop ${vm_path}/${vm} >> /dev/null | |
rm ${vm_path}/${vm}.pid | |
else | |
echo "${vm} is not running..." | |
exit 2 | |
fi | |
fi | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment