gen_ip_stats.sh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2017-2018 Joe Clarke <jclarke@cisco.com>
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. # SUCH DAMAGE.
  26. i41=`/usr/local/bin/snmpget -Oq -v3 -l authPriv -u USER -a SHA -A PW -x AES -X PW 10.66.201.161 ipIfStatsHCInOctets.ipv4.1`
  27. i61=`/usr/local/bin/snmpget -Oq -v3 -l authPriv -u USER -a SHA -A PW -x AES -X PW 10.66.201.161 ipIfStatsHCInOctets.ipv6.1`
  28. o41=`/usr/local/bin/snmpget -Oq -v3 -l authPriv -u USER -a SHA -A PW -x AES -X PW 10.66.201.161 ipIfStatsHCOutOctets.ipv4.1`
  29. o61=`/usr/local/bin/snmpget -Oq -v3 -l authPriv -u USER -a SHA -A PW -x AES -X PW 10.66.201.161 ipIfStatsHCOutOctets.ipv6.1`
  30. i42=`/usr/local/bin/snmpget -Oq -v3 -l authPriv -u USER -a SHA -A PW -x AES -X PW 10.66.201.162 ipIfStatsHCInOctets.ipv4.1`
  31. i62=`/usr/local/bin/snmpget -Oq -v3 -l authPriv -u USER -a SHA -A PW -x AES -X PW 10.66.201.162 ipIfStatsHCInOctets.ipv6.1`
  32. o42=`/usr/local/bin/snmpget -Oq -v3 -l authPriv -u USER -a SHA -A PW -x AES -X PW 10.66.201.162 ipIfStatsHCOutOctets.ipv4.1`
  33. o62=`/usr/local/bin/snmpget -Oq -v3 -l authPriv -u USER -a SHA -A PW -x AES -X PW 10.66.201.162 ipIfStatsHCOutOctets.ipv6.1`
  34. in41=`echo ${i41} | cut -f2 -d' '`
  35. in61=`echo ${i61} | cut -f2 -d' '`
  36. out41=`echo ${o41} | cut -f2 -d' '`
  37. out61=`echo ${o61} | cut -f2 -d' '`
  38. in42=`echo ${i42} | cut -f2 -d' '`
  39. in62=`echo ${i62} | cut -f2 -d' '`
  40. out42=`echo ${o42} | cut -f2 -d' '`
  41. out62=`echo ${o62} | cut -f2 -d' '`
  42. #echo "${in1} ${out1} ${in2} ${out2}"
  43. total4=$(expr \( ${in41} + ${out41} + ${in42} + ${out42} \))
  44. total6=$(expr \( ${in61} + ${out61} + ${in62} + ${out62} \))
  45. ototal4=0
  46. ototal6=0
  47. if [ -f /home/jclarke/cached_ip_stats.dat ]; then
  48. cache=$(cat /home/jclarke/cached_util.dat)
  49. ototal4=$(echo ${cache} | cut -f5 -d' ')
  50. ototal6=$(echo ${cache} | cut -f5 -d' ')
  51. cp -f /home/jclarke/cached_ip_stats.dat /home/jclarke/cached_ip_stats.dat.old
  52. fi
  53. if [ ${total4} -lt ${ototal4} ]; then
  54. total=$(expr ${total4} + ${ototal4})
  55. fi
  56. if [ ${total6} -lt ${ototal6} ]; then
  57. total=$(expr ${total6} + ${ototal6})
  58. fi
  59. echo "${total4} ${total6}" > /home/jclarke/cached_ip_stats.dat