xonotic/misc/infrastructure/cat-if-error.sh

19 lines
263 B
Bash
Raw Normal View History

2012-02-21 13:16:16 +00:00
#!/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"