xonotic/misc/infrastructure/cat-if-error.sh
2012-02-21 14:16:16 +01:00

19 lines
263 B
Bash
Executable File

#!/bin/sh
logfile=$1
shift
if ! lockfile-create "$logfile.lock" >/dev/null 2>&1; then
exit 1
fi
lockfile-touch "$logfile.lock" & lockpid=$!
if "$@" >"$logfile" 2>&1; then
: # all is well
else
cat "$logfile"
fi
kill $lockpid
lockfile-remove "$logfile.lock"