Linux Training

Linux training for private, public & voluntary sector.

0793 572 8612

City LinUX sample scripts - webupd


#!/bin/bash
# $Id: webupd,v 1.56 2019/01/24 13:03:42 fulford Exp fulford $
# $Source: /src/admin/usr/local/etc/RCS/webupd,v $
# $Revision: 1.56 $
# Author C W Fulford.
# Copyright (c) 2012-2019 C W Fulford. 
# Licensed for public use under the LGPL.
# For assistance contact fulford@fulford.net 0709 229 5385
###################################################################
debug=0
cmd=`basename $0`
#set -x
syntax="$cmd [[-c <config_file>] [-d] [[-h]|[-s]] [-S] [-v] <host_name>]|[-V]" 
updates="awstats htdig"
verbose=0
error=`echo $cmd|awk  '/-h/&&/-s/{print "0"}'`
error=${error:=1}
[ $error -eq 0 ] &&{
	echo "$syntax" 
	exit 1 
}
while [ $# -gt 0 ];do
	case $1 in
		-S) static="-staticlinks";shift;;
		-c) config=$2;shift 2;;
		-d) debug=1; set -x;shift ;;
		-h) updates=htdig; shift ;;
		-s) updates=awstats; shift ;;
		-v) verbose=1 ;shift 1;;
		-V) echo "$cmd $Revision: 1.56 $"|awk '{print $1,$3}';exit;;  
		 *) host=$1;shift;;
	esac
done
[ -z $host ] && { echo "syntax: $syntax">&2;exit 1 ;}
config=${config:-/usr/local/etc/webupd.cf}
if [ -r $config ];then
	[ $verbose -gt 0 ] && echo "config = $config"
	eval `sed -ne  '/^'$host':$/,/^$/{/^[ \t].*[^#]/p}' <$config `
else
	echo "$cmd can't find $config">&2
	exit 1
fi
[ $verbose -gt 0 ] && echo "$cmd: updating awstats on $host" 
if echo $updates|grep -q "awstats";then 	
	for s in $sites ;do
		[ $verbose -gt 0 ] &&{
			 echo -n "updating awstats for $s on $host" 
		}
		ssh -q $host "[ -d $viewstats/$s ] ||{
			sudo mkdir -p $viewstats/$s
			sudo chown apache.daemon $viewstats/$s
		}"
		ssh -q $host "cd $awstats;sudo perl awstats.pl -config=$s -update -output $static |sudo dd of=$viewstats/$s/awstats.html &2>/dev/null"
		[ $verbose -gt 0 ] && echo " - done." 
	done
fi
if echo $updates|grep -q "htdig";then
		[ $verbose -gt 0 ] && {
			echo "updating dig for $dig_cf on $host" 
		}
		ssh -q $host "
		for conf in $dig_cf;do
			[ $verbose -gt 0 ] &&{
				 echo "updating dig using \$conf"
			}
			sudo rundig -c /etc/htdig/\$conf;
		done"
fi
######################################################################
# This program is free software: you can redistribute it and or      #
# modify it under the terms of the Lesser GNU General Public License #
# as published by the Free Software Foundation, either version 3 of  #
# the License, or (at your option) any later version.                #
#                                                                    #
# This program is distributed in the hope that it will be useful,    #
# but WITHOUT ANY WARRANTY; without even the implied warranty of     #    
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      #
# GNU General Public License for more details.                       #
#                                                                    # 
# A copy of the Lesser GNU General Public License and the GNU        #
# General Public License is available at                             #
# <http://www.gnu.org/licenses/>.                                    #
######################################################################

The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.