aboutsummaryrefslogtreecommitdiff
path: root/scripts/record-commands
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-01-30 16:16:07 -0600
committerRob Landley <rob@landley.net>2019-01-30 16:16:07 -0600
commita242b5be0b486fb1137c45c87e2867aef2e1fcb3 (patch)
tree92e4d956cf4f39745a26af72e7e88a0c6bb8a325 /scripts/record-commands
parenta8ade49b0566cf0b55b404e0e3c175c9c17d7dc0 (diff)
downloadtoybox-a242b5be0b486fb1137c45c87e2867aef2e1fcb3.tar.gz
Command logging wrapper to help analyze what commands scripts call and how.
Diffstat (limited to 'scripts/record-commands')
-rwxr-xr-xscripts/record-commands33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/record-commands b/scripts/record-commands
new file mode 100755
index 00000000..0201ac31
--- /dev/null
+++ b/scripts/record-commands
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+# Set up command recording wrapper
+
+[ -z "$WRAPDIR" ] && WRAPDIR="$PWD"/record-commands
+[ -z "$WRAPLOG" ] && export WRAPLOG="$PWD"/log.txt && CLEANUP=1
+
+if [ $# -eq 0 ]
+then
+ echo "Usage: WRAPDIR=dir WRAPLOG=log.txt record-commands command..."
+ echo "Then examine log.txt"
+ exit 1
+fi
+
+if [ ! -x "$WRAPDIR/logwrapper" ]
+then
+ make logwrapper
+ mkdir -p "$WRAPDIR" && mv logwrapper "$WRAPDIR" || exit 1
+
+ echo "$PATH" | tr : '\n' | while read DIR
+ do
+ ls "$DIR/" | while read FILE
+ do
+ ln -s logwrapper "$WRAPDIR/$FILE" 2>/dev/null
+ done
+ done
+fi
+
+PATH="$WRAPDIR:$PATH" "$@"
+X=$?
+[ ! -z "$CLEANUP" ] && rm -rf "$WRAPDIR"
+
+exit $X