-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtravis_wait_log
executable file
·28 lines (25 loc) · 1.06 KB
/
travis_wait_log
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
set -e
if [[ "$1" =~ ^[1-9][0-9]*$ ]]; then # check if 1st param is number >0
WAIT=$1; shift # set sleep parameter in minutes
fi
let WAIT=${WAIT:-5}*60 # default sleep time 5 minutes
[[ $1 ]] || exit 1 # exit if no command given as a parameter
finish() {
ERR=$? # store exit code in safe place
trap - ERR EXIT
echo # end dots with new line
if [[ -s "$LOG" ]]; then # display log file only if not empty
echo -e "Last ${LINES:=500} lines of log:" # allow overwrite number of lines
tail -$LINES "$LOG"
fi
kill $CHPID && wait &>>/dev/null # kill child displaying dots
exit $ERR # restore exit code from executed command
}
: ${COLUMNS:=70} # allow overwrite number of dots in one line
echo Executing: $@
while sleep $WAIT; do echo -n .; ((++n%COLUMNS)) || echo; done &
CHPID=$! # store child PID for killing them after task terminate
: >"${LOG:=/tmp/travis_wait.log}" # allow overwrite log filename
trap finish ERR EXIT # display log & kill child at error or normal exit
( eval "$@" ) &>>"$LOG" # use eval here to support env variables before cmd