source: trunk/packs/maint/counterlog.sh @ 17801

Revision 17801, 1.2 KB checked in by jweiss, 22 years ago (diff)
deal with the fact that the counter-id file could be zero length
Line 
1#!/bin/sh
2
3# Usage: counterlog [annotation]
4
5# Syslog a message at user.notice (which goes to wslogger.mit.edu in
6# the normal Athena configuration) containing the hostname, machtype,
7# cputype, Athena version, system identifier, and the annotation if
8# specified.
9
10# The system identifier is a random number chosen the first time this
11# script runs.  It is intended to help distinguish machines which
12# change IP addresses due to DHCP.
13
14# This script is run from the Athena boot script and from a root cron
15# job.
16
17# If you don't want this logging to happen, touch
18# /etc/athena/no-counterlog.
19
20if [ -f /etc/athena/no-counterlog ]; then
21  exit 0
22fi
23
24if [ ! -s /var/athena/counter-id ]; then
25  if [ -r /dev/urandom ]; then
26    dd if=/dev/urandom bs=8 count=1 2>/dev/null | od -x \
27      | awk '{print $2 $3 $4 $5; exit}' > /var/athena/counter-id
28  else
29    echo "" | awk '{srand; printf "%09d\n", int(rand * 999999999); }' \
30      > /var/athena/counter-id
31  fi
32  chmod 644 /var/athena/counter-id
33fi
34
35host=`hostname`
36type=`/bin/athena/machtype`
37ctype=`/bin/athena/machtype -c`
38version=`awk '/./ { a = $5; } END { print a; }' /etc/athena/version`
39id=`cat /var/athena/counter-id`
40annot=$1
41
42logger -p user.notice "counterlog: $host $type $ctype $version $id $annot"
Note: See TracBrowser for help on using the repository browser.