eval_oneprogram.sh
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:2k
源码类别:

SNMP编程

开发平台:

Unix_Linux

  1. #!/bin/sh
  2. #
  3. # eval_oneprogram.sh [-h][-lk] <program> [<program_args>]
  4. #
  5. # CALLED BY: eval_suite.sh
  6. #
  7. #
  8. # Runs <program> and reports how many instances of the strings SUCCESS
  9. # or FAILED occur.
  10. #
  11. #
  12. # FIX Output from $PROGRAM on stderr is separated out and comes first.
  13. #
  14. #
  15. USAGE_LONG='
  16. #
  17. # -h Help.
  18. # -k Save the program output in "__<program_args>__<pid>o".
  19. # -l Long form.  (Short form by default.)
  20. #
  21. # <program> is the executable to run and collect the output of.
  22. '
  23. USAGE="Usage: `basename $0` [-h][-lk] <program>"
  24. #------------------------------------ -o- 
  25. # Globals.
  26. #
  27. AWKFILE="_`basename $0`$$.awk"
  28. SCRIPTFILE=
  29. dolongform=0
  30. dokeepoutput=
  31. TOTALFAILED=0
  32. #------------------------------------ -o- 
  33. # Parse & setup.
  34. #
  35. while [ -n "$1" ]; do
  36. case "$1" in
  37. -k) dokeepoutput=true
  38. ;;
  39. -l) dolongform=1
  40. ;;
  41. -h) echo $USAGE
  42. cat <<BLIK | sed 's/^#//' | sed '1d'    1>&2
  43. $USAGE_LONG
  44. BLIK
  45. exit 0
  46. ;;
  47. *) PROGRAM="$*"
  48. shift `expr $# - 1`
  49. ;;
  50. esac
  51. shift
  52. done
  53. [ -z "$PROGRAM" ] && echo $USAGE && exit 1
  54. SCRIPTFILE="__`echo `basename $PROGRAM` | sed 's/ /_/g'`__$$o"
  55. #------------------------------------ -o- 
  56. # Create awk script.
  57. #
  58. cat <<GRONK >$AWKFILE
  59. BEGIN {
  60. pass = 0
  61. passlist[0] = ""
  62. fail = 0
  63. faillist[0] = ""
  64. longform = $dolongform + 0
  65. }
  66. /SUCCESS/ {
  67. passlist[pass] = $0
  68. pass += 1
  69. }
  70. /FAILED/ {
  71. faillist[fail] = $0
  72. fail += 1
  73. }
  74. END {
  75. printf "$PROGRAM SUCCESS: %dn", pass
  76. printf "$PROGRAM FAILED: %dn", fail
  77. if (longform) {
  78. printf "n"
  79. for (i=0; i<pass; i++)
  80. print passlist[i]
  81. for (i=0; i<fail; i++)
  82. print faillist[i]
  83. }
  84. exit fail
  85. }
  86. GRONK
  87. #------------------------------------ -o- 
  88. # Get and print results.
  89. #
  90. { $PROGRAM $* 2>&1 ; } >$SCRIPTFILE
  91. awk -f $AWKFILE $SCRIPTFILE
  92. TOTALFAILED=$?
  93. rm -f $AWKFILE
  94. [ -z "$dokeepoutput" ] && rm -f $SCRIPTFILE
  95. #------------------------------------ -o- 
  96. # Exit, cleanup.
  97. #
  98. exit $TOTALFAILED