PageRenderTime 29ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/mrtg-2.17.4/contrib/adm-mrtg/adm-mrtg

#
Korn Shell | 149 lines | 93 code | 26 blank | 30 comment | 3 complexity | 85ea92237c3da4d41a5e75aea88a195e MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/ksh
  2. # This script organizes config files for MRTG
  3. # and restarts the MRTG processes cleanly.
  4. # Author: Scott Ripley, U.S. House of Representatives
  5. # Version: 1.0 (and all that a 1.0 release entails)
  6. # Contact: scott.ripley@mail.house.gov
  7. # Copyright: (C) 2001 Scott Ripley
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # See the GNU General Public License for more details.
  16. # Change these directores to match your configuration for MRTG
  17. MRTG=/usr/local/mrtg/bin
  18. # TARHOME is the location of the back-up files. It should be another volume
  19. TARHOME=/usr/local/mrtg/bin
  20. # Location of log files
  21. WEBHOME=/usr/local/apache/htdocs/mrtg_images
  22. cd $MRTG
  23. # Initialize the variables and temp files
  24. typeset -i CFGLINE
  25. typeset -i MAXLINE
  26. CFGLINE=1
  27. MAXLINE=1
  28. CFG="$MRTG"/mrtgcfgs.run
  29. CFGNUM="$MRTG"/cfgnum.run
  30. MCNAME=`uname -n`
  31. EXIT=N
  32. DATE=`date '+%m%d%y%H%M' `
  33. # TARHOME is the location of the back-up files. It should be another volume
  34. TARHOME=/usr/local/mrtg/bin
  35. WEBHOME=/usr/local/apache/htdocs/mrtg_images
  36. # Set tabs for display columns
  37. stty tabs
  38. tabs 10,30,40,45
  39. # Main loop
  40. while [ "$EXIT" = N ]
  41. do
  42. # reads the pid files and inputs them into a file
  43. ls -go *pid | sed 's/[ ][ ]/ /g' | cut -d"." -f1 > "$CFG"
  44. nl -bt -nrz -w2 "$CFG" > "$CFGNUM" # numbers the lines in the file
  45. # sets the number of configs loaded, for error testing
  46. MAXLINE=`wc -l "$CFG" | cut -d" " -f7 `
  47. clear
  48. printf "\n\nThe following MRTG configs are running on "$MCNAME":\n"
  49. printf "\n\tConfig name\t\tRunning Since\n"
  50. printf "\t-----------\t\t-------------\n"
  51. # prints out the appropriate fields on-screen
  52. nawk ' { print "\t" $1,$8".cfg \t\t" $5,$6,$7 } ' "$CFGNUM"
  53. printf "\n"
  54. printf " Which file would you like to reload? (b to back-up, q to quit) \c"
  55. read X
  56. case "$X" in
  57. [qQ] )
  58. EXIT=Y # I quit!
  59. ;;
  60. [bB] )
  61. printf "\n Backup *.cfg & *.log files? \c"
  62. read V
  63. case "$V" in
  64. 'y' | 'Y' )
  65. CNAME=MRTG_"$DATE".cfgs.tar
  66. tar cvf "$TARHOME"/"$CNAME" "$MRTG"/*.cfg
  67. chmod 0400 "$TARHOME"/"$CNAME"
  68. LNAME=MRTG_"$DATE".logs.tar
  69. find "$WEBHOME" | egrep -e "\.log$|\.old$" > mrtgtar.run
  70. tar cvf "$LNAME" -I mrtgtar.run
  71. chmod 0600 "$TARHOME"/"$CNAME"
  72. chmod 0600 "$TARHOME"/"$LNAME"
  73. # printf "\nGzipping files..."
  74. # gzip "$TARHOME"/"$CNAME"
  75. # gzip "$TARHOME"/"$LNAME"
  76. printf "\nConfig files backed up to `ls "$TARHOME"/MRTG_"$DATE".cfg*` "
  77. printf "\nLog files backed up to `ls "$TARHOME"/MRTG_"$DATE".log*` "
  78. printf "\nPress return to continue..."
  79. read U
  80. ;;
  81. * )
  82. printf "\nBackup aborted."
  83. sleep 3
  84. ;;
  85. esac
  86. ;;
  87. [0-9][0-9] ) # If the number entered is between 0 and 99...
  88. # and if the number is <= the no. of configs loaded
  89. if [ "$X" -le "$MAXLINE" ] #
  90. then
  91. FILE=`sed -n ''$X'p' "$CFGNUM" | cut -d" " -f11 ` # put filename into $FILE
  92. echo " Okay to restart "$FILE".cfg? \c"
  93. read Y
  94. case "$Y" in
  95. 'y' | 'Y' )
  96. FKILL=`cat "$MRTG""/""$FILE"".pid"` # Set the variable with the PID
  97. kill -9 $FKILL # Kill it
  98. rm $MRTG/$FILE".pid" # Remove the file
  99. $MRTG"/mrtg" $FILE".cfg" # Restart MRTG with the config file
  100. sleep 8 # Wait for new PID file to be created
  101. echo "New PID for "$FILE".cfg is `cat "$MRTG"/"$FILE".pid` "
  102. ;;
  103. *)
  104. echo "\nRestart aborted!"
  105. ;;
  106. esac
  107. else
  108. echo "Entry Invalid! Press return to continue..."
  109. read ZZ
  110. fi
  111. ;;
  112. *)
  113. echo "Entry Invalid! Press return to continue..."
  114. read ZZ
  115. ;;
  116. esac
  117. done
  118. # For security/housekeeping reasons, we clean out the temp files here.
  119. cat /dev/null > "$MRTG"/mrtgcfgs.run
  120. cat /dev/null > "$MRTG"/cfgnum.run
  121. cat /dev/null > "$MRTG"/cfgsed.run
  122. cat /dev/null > "$MRTG"/mrtgtar.run
  123. exit 0