tcnowstat
上传用户:shbosideng
上传日期:2013-05-04
资源大小:1555k
文件大小:2k
源码类别:

SNMP编程

开发平台:

C/C++

  1. #!/bin/bash
  2. grep_it() {
  3.   value="`cat $TEMP_FILE | head -$1 | tail -1`"
  4.   perc="`expr "$value" * 100 / "${MAXB:=1}"`"
  5.   color=""
  6.   if [ ${perc:=0} -ge 90 ]
  7.   then
  8.     color=" bgcolor=red"
  9.   elif [ ${perc:=0} -ge 80 ]
  10.   then
  11.     color=" bgcolor=yellow"
  12.   elif [ ${perc:=0} -le 25 ]
  13.   then
  14.     color=" bgcolor=cyan"
  15.   else
  16.     color=" bgcolor=lightgreen"
  17.   fi
  18.   echo "      <td>$value</td><td$color>${perc}%</td>"
  19. }
  20. ###############################################################################
  21. export DIR=/usr/local/mrtg-2.8.12/local-config/www/tcusercount
  22. export MACH="`echo "$1" | sed -e 's/+/_/g'`"
  23. export MAXB="$2"
  24. export TEMP_FILE=/tmp/tcnowstat.$$
  25. ###############################################################################
  26. if [ ! -r "$DIR/${MACH}.html" ]
  27. then
  28.   exit
  29. fi
  30. cat "$DIR/${MACH}.html" |   
  31.   grep '<!-- ' |           
  32.   grep "in " |              
  33.   cut -d' ' -f4 >$TEMP_FILE
  34. trap "rm -f $TEMP_FILE ; exit" 1 2 15
  35. echo ""
  36. echo "  <table border>"
  37. echo "    <tr>"
  38. echo "      <td></td>"
  39. echo "      <td colspan=2 align=center>Max</td>"
  40. echo "      <td colspan=2 align=center>Avg</td>"
  41. echo "      <td colspan=2 align=center>Now</td>"
  42. echo "    </tr>"
  43. echo "    <tr>"
  44. echo "      <td>Day</td>"
  45. grep_it 1
  46. grep_it 2
  47. grep_it 3
  48. echo "    </tr>"
  49. echo "    <tr>"
  50. echo "      <td>Week</td>"
  51. grep_it 4
  52. grep_it 5
  53. grep_it 6
  54. echo "    </tr>"
  55. echo "    <tr>"
  56. echo "      <td>Month</td>"
  57. grep_it 7
  58. grep_it 8
  59. grep_it 9
  60. echo "    </tr>"
  61. echo "    <tr>"
  62. echo "      <td>Year</td>"
  63. grep_it 10
  64. grep_it 11
  65. grep_it 12
  66. echo "    </tr>"
  67. echo "  </table>"
  68. echo ""
  69. trap - 1 2 15
  70. rm -f $TEMP_FILE 2>/dev/null