#!/bin/bash ssh UNAME@SERVERIPADDRES -N -L 5900:192.168.0.90:5900 & # 192.168.0.90 is the target computers ip PID=$! sleep 5 open /Applications/"My Utilities"/"admin utilities"/"Remote Access"/127.0.0.1.vncsession # path to where the vnc session file is located sleep 5 PID2=`ps auxwww|grep VNCDimension.app | grep -v grep | awk '{print $2}'` # This loop will check every minute to see if the VNC process has quit or not. # When it does, then the ssh pid will be killed. while [ -n "$PID2" ] do PID2=`ps -p $PID2 -o pid | grep $PID2` sleep 60 # This number can be adjusted for a different time to check. done kill $PID exit