I sometimes need to wrap shell commands with monitoring, logging, or other actions. This technique is simliar to yielding in ruby. The example just pops out some text before and after the command, but you can put just about anything in there.

Note: This is extremely naive and has no error detection, etc. etc.

#!/bin/bash

# usage:
#   - wrapper.sh do-list ls -la
#   - wrapper.sh import-job /usr/local/bin/import param1 param2

TIMESTAMP=$(date +%s) MONITOR_NAME=$1
shift 1

COMMAND=$@ echo "$MONITOR_NAME-$TIMESTAMP START"$COMMAND

echo "$MONITOR_NAME-$TIMESTAMP STOP"


photo: Sigmund on Unsplash