Merge branch 'release-2.140.114'
[feisty_meow.git] / scripts / testing / rounder.sh
1 #!/bin/bash
2
3 # sample the first argument to make sure it's not empty.
4 # we can't know if the command is really valid or not, but it at least
5 # needs to not be empty.
6 test_to_run="$1"
7
8 if [ -z "$test_to_run" ]; then
9   echo "
10 rounder: this script requires a test or program to run as the first parameter.
11
12 the parameter can be an arbitrarily complex bash command as long as it's
13 escaped properly.  for example, this command will check a directory size and
14 then sleep for 10 seconds:
15
16   rounder  '\du -s ~/a_folder_i_watch; sleep 10'
17
18 rounder will run this check, snoozing in between checks, until the universe
19 ends or something intervenes.  note that without the sleep, the check would
20 occur very rapidly and spew output.
21 "
22   exit 1
23 fi
24
25 trashdir="$(mktemp -d "$TMP/rounder.XXXXXX")"
26
27 echo "Running command: $*"
28 echo "Storing log files in: $trashdir"
29
30 round=0
31 while true; do
32   round=$((round+1))
33   echo ============================
34   echo round $round commencing
35   outputfile="$trashdir/run_round_${round}.log"
36 echo real cmd:
37 echo "${@}" 
38   eval "${@}" 2>&1 | tee $outputfile
39   if [ ${PIPESTATUS[0]} -ne 0 ]; then
40     echo FAILURE IN RUN $round
41     break
42   fi
43   echo round $round successful.
44 done 
45