Skip to content

Instantly share code, notes, and snippets.

@jhuebsch
Created November 14, 2012 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jhuebsch/4069502 to your computer and use it in GitHub Desktop.
Save jhuebsch/4069502 to your computer and use it in GitHub Desktop.
Control parallels VM via command line and mount remote users home dir as network share with sshfs
# Parallels VM management
# start/pause/resume Parallels VM. When starting VM mounts VM users home dir (default) as
# network share on local machine using fuse4x and sshfs. When pausing VM, unmounts network
# share before pausing VM.
vmsb() {
# parallels VM you want to controll, find availble names with "prlctl list -a"
VM=""
# connection string for user on $VM ie user@virtualmachine
CONNECT=""
# Aboslute path "pwd -P" of a folder your user owns that can be used as the
# mountpoint for the network share
MNTPOINT=""
# Current running status of $VM
VMSTATUS=`prlctl list $VM -o status --no-header`;
# if starting vm, start vm then wait then mount network share
if [ "$1" = "start" ] || [ "$1" = "resume" ]
then
case "$VMSTATUS" in
"running" )
echo "$VM is already running.";
;;
"stopped" )
echo "prlctl start $VM";
prlctl start $VM;
;;
"paused" )
echo "prlctl resume $VM";
prlctl resume $VM;
;;
"suspended" )
echo "prlctl start $VM";
prlctl resume $VM;
;;
esac
# mount network share, only if it hasn't already been mounted
if [ ! -f "$MNTPOINT/.bash_logout" ]
then
# give time for vm to boot
COUNT=0
while [ $VMSTATUS != "running" ]
do
(( COUNT++ ))
printf "\rWaiting for $VM to finish booting: $COUNT";
sleep 1;
VMSTATUS=`prlctl list $VM -o status --no-header`;
done
echo -en \\033[0\;32m "\nMounting network share:" \\033[0m"\n";
echo "sshfs $CONNECT: $MNTPOINT";
sshfs "$CONNECT": "$MNTPOINT";
fi
# if pausing or stopping vm, unmount mounted sshfs mounted network share then pause or stop VM
elif [ "$1" = "pause" ] || [ "$1" = "stop" ]
then
# no need to run pause if machine isn't running
if [ ! "$VMSTATUS" = "running" ]
then
echo -en \\033[0\;32m "$VM is not currently running, it is currently $VMSTATUS" \\033[0m"\n";
else
# only unmount if network share is mounted
if [ -f "$MNTPOINT/.bash_logout" ]
then
echo -en \\033[0\;32m "Unmounting network share:" \\033[0m"\n";
echo "diskutil unmount $MNTPOINT";
diskutil unmount "$MNTPOINT";
fi
# while for network share to unmount before continuing.
COUNT=0
while [ -f "$MNTPOINT/.bash_logout" ]
do
echo "$COUNT";
sleep 1;
(( COUNT++ ))
done
# Never stop as that is like unplugging the VM.
echo "prlctl pause $VM";
prlctl pause $VM;
fi
else
echo "prlctl $@ $VM";
prlctl $@ $VM;
fi
}
@vidrowan
Copy link

Hey jhuebsch,
I forked your gist and added some help documentation. Not sure how to do a pull request on a gist?
https://gist.github.com/4091028

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment