--- 1.6/nemrun	2011-02-18 12:35:35.000000000 -0800
+++ 1.7/nemrun	2011-03-11 16:31:04.267898173 -0800
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# NemRun v1.6 - Nephyrin@Doublezen.net, 02/18/2011
+# NemRun v1.7 - Nephyrin@Doublezen.net, 03/11/2011
 # run without arguments for usage
 # The newest version is always available at http://nephyrin.net/tools/nemrun
 
@@ -40,6 +40,8 @@
 	SHAREDKILLCOMMAND="quit"
 	# Script to run when an update is found
 	NOTIFYCMD=""
+	# Script to run after updates complete
+	AFTERNOTIFYCMD=""
 	# Script to run INSTEAD of -sharedscreens killing.
 	SHUTDOWNSCRIPT=""
 	# Update before rebooting?
@@ -82,7 +84,7 @@
 function usage
 {
 echo "
-NemRun v1.6 - Nephyrin@Doublezen.net, 02/18/2011
+NemRun v1.7 - Nephyrin@Doublezen.net, 03/11/2011
 
 Usage: ./nemrun [-nemlog file [-nemlogtimestamp format]] [-cleandownloads age]
   [-autoupdate -steamdir dir -srvdir dir [(-sharedscreens screen[,screen[,...]]
@@ -126,6 +128,9 @@
 		   command to run when an update is found, and the script begins
 		   to apply it. IE '-notifycmd ./emailTheAdmins.sh'
 		   
+		-afternotifycmd command
+		   like -notifycmd, but run after the update has been completed
+		   
 		-steamdir dir
 		   the dir (relative to working dir) where ./steam is
 
@@ -294,10 +299,10 @@
 	if test -f ./update.lock; then
 		local procs pid
 		pid=$(cat ./update.lock)
-		if test "$pid" -gt 0; then
+		if test ! -z "$pid" && test "$pid" -gt 0; then
 			procs=$(( `ps -p "$pid" 2>/dev/null | wc -l` - 1 ))
 		fi
-		if test "$procs" -eq 0; then
+		if test -z "$procs" || test "$procs" -eq 0; then
 			log ":: verifylock failed: cleaning bad lock file"
 			rm -f ./update.lock
 			return 1 # Lock was corrupt and killed
@@ -439,7 +444,7 @@
 					fi
 					
 					local dirstr
-					if test ! -z "$srvdir"; then
+					if test ! -z "$SRVDIR"; then
 						dirstr="-dir \"$SRVDIR\""
 					fi
 					
@@ -464,6 +469,10 @@
 				fi
 			done
 			log ":: Update complete"
+			if test ! -z "$AFTERNOTIFYCMD"; then
+				log ":: Running -afternotifycmd \"$AFTERNOTIFYCMD\""
+				$AFTERNOTIFYCMD
+			fi
 			cleandownloads
 			if test ! -z "$UPDATEFIRST"; then
 				log ":: -updatefirst specified, rebooting other servers now that update is ready."
@@ -612,6 +621,10 @@
 					NOTIFYCMD="$2"
 					shift
 					;;
+				'-afternotifycmd')
+					AFTERNOTIFYCMD="$2"
+					shift
+					;;
 				'-sharedkillcommand')
 					SHAREDKILLCOMMAND="$2"
 					shift
