kshell: add -l option to log output to /tmp/kshell$$

Change-Id: I1e3d81291f77501cff20f9018b221cb16802a305
diff --git a/kshell.sh b/kshell.sh
index 386e3bd..db49a73 100755
--- a/kshell.sh
+++ b/kshell.sh
@@ -1,5 +1,14 @@
 #! /bin/bash
-# Connect to the kata console shell
+# Connect to the kata console shell & optionally tee output
+# to /tmp/kshell*.log
+
+# Usage: kshell [-l] [port]
+
+LOG_OUTPUT=
+if [[ "$1" == "-l" ]]; then
+    LOG_OUTPUT="yes"
+    shift
+fi
 
 PORT=${1:-1234}
 DIR_NAME=$(dirname $(realpath $0))
@@ -10,4 +19,8 @@
 stty sane -echo -icanon
 
 echo "Access port: ${SOCKET_PORT}"
-socat "TCP:localhost:${SOCKET_PORT}" -
+if [[ "${LOG_OUTPUT}" == "yes" ]]; then
+    socat "TCP:localhost:${SOCKET_PORT}" - | tee /tmp/kshell.$$.log
+else
+    socat "TCP:localhost:${SOCKET_PORT}" -
+fi