run-in-pagsh: Figure out what user we're running as
[clinton/scripts.git] / run-in-pagsh
index a8bcef8..5ef0e24 100755 (executable)
@@ -51,6 +51,18 @@ K5PID=$HOME/.run/$1.pid
 shift
 CMD="$*"
 
+# Try to deduce the user we're running as.
+if test -z "$USER"; then
+    if test -n "$LOGNAME"; then
+        USER=$LOGNAME
+    elif test -n "$HOME"; then
+        USER=$(basename "$HOME")
+    else
+        echo "Error: cannot deduce your username"
+        exit 1
+    fi
+fi
+
 # Your keytab file.
 KTAB=/etc/keytabs/user.daemon/$USER