![]()
logger(1) to record the setting of the clock to the
system log. This isn't necessary, but it is a handy way of seeing how
much the system clock drifts over time. My syslog.conf sends all
these local0 messages to /var/log/netdate, so they don't clutter
up any more important log file. I run this script from cron
every hour, so my clock is normally less than a second out of sync with
that at ntp.demon.co.uk, which I'm presuming is very accurate.
#!/bin/sh
# clock-sync: update system clock from Demon ntp server;
# and write new date to CMOS if successful
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
progname=`basename $0`
if netdate tcp ntp.demon.co.uk | logger -p local0.notice -t clock-sync
then
hwclock —systohc --utc
exit 0
else
logger -p local0.notice "$progname failed" -t clock-sync
exit 1
fi
The first script, updateweblog, gets the records I'm interested in from the main log file. It's a shared server, so this is more efficient.
#!/bin/sh
#updatelog: get latest log records from master file
grep dunne /var/log/httpd/access_log > $HOME/tmp/log
#!/bin/sh
#httpdlog: query the httpd access log for my data
file=$HOME/tmp/log
name=`basename $0`
case $name in
corelog) site='/~dunne//*index.html' ;;
linuxlog) site='-v ireland|weblog|index.html' ;;
irelandlog) site='/~dunne/ireland/' ;;
webloglog) site='/~dunne/weblog/' ;;
alllog) site='/~dunne/' ;;
esac
case $1 in
#summary: how many
-s)
egrep "`date +'%d/%b'`" $file |
egrep $site |
awk '{print $1}' | sort +0 -1 | uniq | wc -l
;;
#hostname/uniq-ip: who
-h)
egrep "`date +'%d/%b'`" $file |
egrep $site |
awk '{print $1}' | sort +0 -1 | uniq
;;
#detail: what
-d)
egrep "`date +'%d/%b'`" $file |
egrep $site
;;
esac
cron.
#!/bin/sh
#webstats: run httpdlog in a variety of ways
updateweblog
for i in core linux ireland weblog
do
"$i"log -s | mail -s "$i summary log `date`" dunne
for j in `"$i"log -u`
do
echo "$j `host $j`" | awk '{printf "%s\t%s\n", $1, $NF}'
done | mail -s "$i ip/hostname log `date`" dunne
"$i"log -d | mail -s "$i detailed log `date`" dunne
done
diald, but it's trivial to modify for
other daemons.
#!/bin/sh
#check-diald
if [ -f /var/run/diald.pid ]
then
pid=`cat /var/run/diald.pid`
result=`ps ax|grep $pid|grep -v grep`
case $result in
"") /usr/sbin/diald; exit 1 ;;
*) exit 0 ;;
esac
else
/usr/sbin/diald
exit 2
fi
named on my server isn't the pirmary or secondary controllor for
that server's hostname. Clearly, named should do something sensible
when asked about that name when the Net link is down. So, when the link
was down, I used to restart named with an alternate config. file
and /var/named files, which mapped the server hostname onto the
ip address of the ethernet adaptor rather than the Net adaptor.
#!/bin/sh
pid=`cat /var/run/named.pid`
case $pid in
"") exit 1;;
esac
case $1 in
netup)
kill $pid
/usr/sbin/named -u named -g namedgroup -b /etc/named.conf.netup
;;
netdown)
kill $pid
/usr/sbin/named -u named -g namedgroup -b /etc/named.conf.netdown
;;
*)
kill -1 $pid
;;
esac
cron every quarter.
#!/bin/sh
#trim-log-files
cd /var/log || exit 1
for i in $(find . -type f -maxdepth 1)
do
filename=$(echo $i | sed 's?^\./\(.*\)?\1?')
cp -p $i old/$(date +'%Y%m%d').$filename
> $i
done
cd /var/log/httpd || exit 2
for i in $(find . -type f -maxdepth 1)
do
filename=$(echo $i | sed 's?^\./\(.*\)?\1?')
cp -p $i old/$(date +'%Y%m%d').$filename
> $i
done
sendmail.cf to block mail based
on the content of other headers.
#!/bin/sh
#checkreject: look in mail log for mail blocked by access db or other sendmail
#rules
grep "$(date '+%b %_d')" /var/log/mail |
grep 'reject='
[back to Scripts index] [back to Linux, Unix, etc] [Main Site] [Weblog]
Contents licensed under the GPL