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 | |
---|
20 | if [ -f /etc/athena/no-counterlog ]; then |
---|
21 | exit 0 |
---|
22 | fi |
---|
23 | |
---|
24 | if [ ! -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 |
---|
45 | fi |
---|
46 | |
---|
47 | host=`hostname` |
---|
48 | type=`/bin/athena/machtype` |
---|
49 | ctype=`/bin/athena/machtype -c` |
---|
50 | version=`awk '/./ { a = $5; } END { print a; }' /etc/athena/version` |
---|
51 | id=`cat /var/athena/counter-id` |
---|
52 | annot=$1 |
---|
53 | |
---|
54 | logger -p user.notice "counterlog: $host $type $ctype $version $id $annot" |
---|