File:  [Local Repository] / badi / public_scripts / awstats_update_all / awstats_update_all
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Tue Aug 31 01:55:03 2010 UTC (13 years, 7 months ago) by adi
Branches: MAIN
CVS tags: HEAD
comment corrected, pretty printing

    1: #!/bin/sh
    2: 
    3: # Update all awstats sites there is a config file for
    4: # This script runs awstats -update for all sites a config file
    5: # exists in the awstats config dir. It runs the update process in parallel
    6: # for several sites at once. Give the command line argument "-q" to suppress
    7: # all but error output.
    8: 
    9: # (c) 2010 under GPL v2 by Adrian Zaugg.
   10: 
   11: 
   12: # awstats main script
   13: AWSTATS_BIN="/usr/lib/cgi-bin/awstats.pl"
   14: 
   15: # awstats configuration directory
   16: CONF_DIR="/etc/awstats"
   17: 
   18: # normal awstats config files have this extension
   19: CONF_EXT="conf"
   20: 
   21: # File to exclude
   22: # Exclude this file, which isn't a config file for awstats, but
   23: # also resides in the config directory. Note: Only
   24: # files with an extension $CONF_EXT are considered anyway. 
   25: CONF_TEMPLATE="awstats.default"
   26: 
   27: # Run with this priority (0: normal - 19: friendly)
   28: NICENESS=16
   29: 
   30: # Maximum awstats update processes to run at once
   31: MAX_PROCESSES=8
   32: 
   33: # Wait that many seconds when MAX_PROCESSES are running 
   34: # to retry starting new update processes
   35: RETRY=2
   36: 
   37: 
   38: 
   39: # ----don't edit below this line-----
   40: 
   41: # default to babbly, -q suppress output
   42: SPEAK=true
   43: if [ "$1" = "-q" ]; then
   44: 	SPEAK=false
   45: fi
   46: 
   47: function count_proc() {
   48: 	# count how many instances are already running
   49: 	COUNT_PROC=$(ps -o command -u "$(id -u)" | egrep -cwe '^(/bin/sh|/usr/bin/perl)* *'"$AWSTATS_BIN")
   50: }
   51: 
   52: function do_update() {
   53: 	# call awstats
   54: 	if $SPEAK; then 
   55: 		nice -n "$NICENESS" "$AWSTATS_BIN" -update -config="$site" &
   56: 	else
   57: 		# Print errors only
   58: 		nice -n "$NICENESS" "$AWSTATS_BIN" -update -config="$site" > /dev/null &
   59: 	fi
   60: }
   61: 
   62: 
   63: # call awstats for each configured domain
   64: COUNT_PROC=0
   65: CURRENT_DIR="$(pwd)"
   66: cd "$CONF_DIR"
   67: for conf in *.$CONF_EXT; do
   68: 
   69: 	notstarted=true
   70:         
   71: 	# control number uf update processes
   72: 	while [ $notstarted = true ]; do
   73: 		count_proc
   74: 		if [ $COUNT_PROC -lt $MAX_PROCESSES ]; then
   75: 			# exclude the template file
   76: 			if [ "$conf" != "$CONF_TEMPLATE" ]; then
   77: 				site="$(echo "$conf" | sed -e "s/^awstats\.\(.*\)\.conf$/\1/")"
   78: 				$SPEAK && echo "`date "+%Y-%m-%d %H:%M:%S"`: Starting update for $site (already running: $COUNT_PROC)."
   79: 				do_update
   80: 			fi
   81: 			notstarted=false
   82: 			let "site_count += 1"
   83: 			break;
   84: 		fi
   85: 
   86: 		sleep "$RETRY"
   87: 	done
   88: 
   89: done
   90: cd "$CURRENT_DIR"
   91: 
   92: 
   93: # wait for all processes to finish
   94: count_proc
   95: if [ $COUNT_PROC -gt 0 ]; then
   96: 	$SPEAK && echo "`date "+%Y-%m-%d %H:%M:%S"`: All jobs started - $COUNT_PROC process(es) still runnning. Waiting..." 
   97:         
   98: 	# wait for processes to finish
   99: 	while [ $COUNT_PROC -gt 0 ]; do
  100: 		sleep "$RETRY"
  101: 		count_proc
  102: 	done
  103: fi
  104: 
  105: $SPEAK && echo "`date "+%Y-%m-%d %H:%M:%S"`: Finished. Statistics for $site_count sites updated."
  106: exit 0

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>