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

Revision 20409, 1.7 KB checked in by ghudson, 20 years ago (diff)
Try to generate the same counter ID each time we reinstall.
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  case `uname` in
26  Linux)
27    # The output of "hostid" is derived from the machine's IP address,
28    # which isn't the end of the world, but it could result in
29    # duplicate counter IDs when two machines generate their IDs on
30    # the same address (due to DHCP, cluster-services install
31    # addresses, etc.).  Use the MAC address of the first network
32    # device listed in NETDEV, if possible; then fall back to hostid.
33    netdev=`. /etc/athena/rc.conf; echo "${NETDEV%%,*}"`
34    id=`ifconfig "$netdev" | sed -ne 's/://g' -e 's/^.*HWaddr \(.*\)$/\1/p'`
35    : ${id:=`hostid`}
36    ;;
37  SunOS)
38    # The output of "hostid" is taken from the CPU board's ID prom, so
39    # should be unique across machines.
40    id=`hostid`
41    ;;
42  esac
43  echo "$id" > /var/athena/counter-id
44  chmod 644 /var/athena/counter-id
45fi
46
47host=`hostname`
48type=`/bin/athena/machtype`
49ctype=`/bin/athena/machtype -c`
50version=`awk '/./ { a = $5; } END { print a; }' /etc/athena/version`
51id=`cat /var/athena/counter-id`
52annot=$1
53
54logger -p user.notice "counterlog: $host $type $ctype $version $id $annot"
Note: See TracBrowser for help on using the repository browser.