loopcheck.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. # This script is in the public domain
  3. # POSIX shell solution for named pipes and pipestatus,
  4. # http://shell.cfajohnson.com/cus-faq-2.html#Q11
  5. # run() {
  6. # j=1
  7. # while eval "\${pipestatus_$j+:} false"; do
  8. # unset pipestatus_$j
  9. # j=$(($j+1))
  10. # done
  11. # j=1 com= k=1 l=
  12. # for a; do
  13. # if [ "x$a" = 'x|' ]; then
  14. # com="$com { $l "'3>&-
  15. # echo "pipestatus_'$j'=$?" >&3
  16. # } 4>&- |'
  17. # j=$(($j+1)) l=
  18. # else
  19. # l="$l \"\$$k\""
  20. # fi
  21. # k=$(($k+1))
  22. # done
  23. # com="$com $l"' 3>&- >&4 4>&-
  24. # echo "pipestatus_'$j'=$?"'
  25. # exec 4>&1
  26. # eval "$(exec 3>&1; eval "$com")"
  27. # exec 4>&-
  28. # j=1
  29. # while eval "\${pipestatus_$j+:} false"; do
  30. # eval "[ \$pipestatus_$j -eq 0 ]" || return 1
  31. # j=$(($j+1))
  32. # done
  33. # return 0
  34. # }
  35. # # https://mywiki.wooledge.org/Bashism has another solution:
  36. # # mkfifo fifo; command2 <fifo & command1 >fifo; echo "$?"
  37. while true; do
  38. if [ "$1" = "" ]; then
  39. echo All
  40. taskset 1 make check || break;
  41. else
  42. echo One
  43. LOGFILE="test_`date "+%m.%d-%H:%M:%S"`.log"
  44. taskset 01 $1 2>&1 | tee $LOGFILE | grep -v DEBUG;
  45. # TODO: Replace $PIPESTATUS with more portable code
  46. if [ "${PIPESTATUS[0]}" != "0" ]; then
  47. echo "Failed";
  48. date;
  49. break;
  50. fi
  51. fi
  52. grep cadet test_*.log | grep -B 10 ERROR && break
  53. grep cadet test_*.log | grep -B 10 Assert && break
  54. ls core* > /dev/null 2>&1 && break
  55. done