rcain

scl bash create plesk vhosts logwatch configuration

Mar 28th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ###########################################################################
  4. ## Script to create conf files and script links on a Plesk
  5. ## server that monitor all the apache log files
  6. ##
  7. ## Visit blog.surgeons.org.uk for updates
  8. ##
  9. ## mod jrc 280313 - rob cain - http://systemcore.co.uk :
  10. ## created this working version (scl_mk_vhosts_logwatch_configs.sh)
  11. ## from original draft http://blog.surgeons.org.uk/2008/02/monitoring-all-virtual-hosts-on-plesk.html
  12. ## by Neville Dastur (160208)
  13. ##
  14. ############################################################################
  15.  
  16. ## Location of the virtual hosts directories
  17. vhost_root=/var/www/vhosts/
  18.  
  19. ## Various logwatch directories
  20. dir_services="/etc/logwatch/conf/services"
  21. dir_logfiles="/etc/logwatch/conf/logfiles"
  22. dir_scripts="/etc/logwatch/scripts/services"
  23. http_script="/usr/share/logwatch/scripts/services/http"
  24.  
  25. ## Now iter over each directory
  26. for domain in $( ls -Ichroot -Idefault $vhost_root ); do
  27. if [ -d "${vhost_root}${domain}" ]
  28. then
  29. echo "Making services logwatch enteries for ${domain}"
  30. domain_us=`echo $domain | tr . _ | tr '[:upper:]' '[:lower:]'`
  31. (
  32. cat << END_OF_SERVICES_CONF
  33.  
  34. ###########################################################################
  35. # Configuration file for $domain http filter
  36. # See blog.surgeons.org.uk for updates ###########################################################################
  37. Title = "httpd - $domain"
  38.  
  39. # Which logfile group...
  40. LogFile = http_$domain_us
  41. END_OF_SERVICES_CONF
  42. ) > ${dir_services}/http_${domain_us}.conf
  43.  
  44.  
  45. echo "Making logfiles logwatch entries for ${domain}"
  46. (
  47. cat << END_OF_LOGFILES_CONF
  48. ########################################################
  49. # Define log file group for http_$domain_us
  50. # See blog.surgeons.org.uk for updates
  51. #######################################################
  52. LogFile = /var/www/vhosts/$domain/statistics/logs/access_log
  53. LogFile = /var/www/vhosts/$domain/statistics/logs/access_log.processed
  54. LogFile = /var/www/vhosts/$domain/statistics/logs/access_ssl_log
  55. LogFile = /var/www/vhosts/$domain/statistics/logs/access_ssl_log.processed
  56.  
  57. # If the archives are searched, here is one or more line
  58. # (optionally containing wildcards) that tell where they are...
  59. # If you use a "-" in naming add that as well -mgt
  60.  
  61. Archive = /var/www/vhosts/$domain/statistics/logs/access_log.processed.?.gz
  62. Archive = /var/www/vhosts/$domain/statistics/logs/access_ssl__log.processed.?.gz
  63.  
  64. # Expand the repeats (actually just removes them now)
  65. *ExpandRepeats
  66.  
  67. # Keep only the lines in the proper date range...
  68. *ApplyhttpDate
  69. END_OF_LOGFILES_CONF
  70. ) > ${dir_logfiles}/http_${domain_us}.conf
  71.  
  72.  
  73. ## Make the script links
  74. echo "Creating script link for ${domain}"
  75. ln -s ${http_script} ${dir_scripts}/http_${domain_us}
  76.  
  77. fi
  78.  
  79. done
Add Comment
Please, Sign In to add comment