#!/bin/sh

node=`uname -n| sed -e 's/\([^\.]\)\..*/\1/'`
gang=`gang`

farmlet=/usr/local/etc/farmlets/$gang-alla
filebase=/tmp/sel-

output=${1:-/dev/tty}
if [ `echo $output | grep -c /dev/` -eq 0 ] ; then 
  rm -f $output
fi

cat << EOF >>$output
<html> <head> <title>$gang Cluster System Event Log Status Page</title> </head>
<body>
<body bgcolor="#ffffff" text=#a0a0ff">
<meta http-equiv="Refresh" content="900">
<h1><center>$gang Cluster SEL Fetch Begin: `date`</center><h1>
<hr>
EOF

if [ -z "${2-}" ] ; then
  for i in `cat $farmlet`; do
   date > $filebase$i
   enrsh $i '. /fnal/ups/etc/setups.sh;setup ipmi; $IPMI_DIR/selread ' >> $filebase$i &
  done
  #wait
  sleep 30 # wait doesn't work if rsh fails ???
fi

cat << EOF >>$output
<h1><center>$gang Cluster SEL Fetch Done : `date`</center><h1>
<hr>
EOF

cat << EOF >>$output
<table bgcolor="#dfdff0" nosave >
<tr><td align=center><b>Item</b></td>
EOF

for i in `cat $farmlet`; do
  cat << EOF >>$output
<h2><center>System Event Log for node $i</center><h2>
<pre>
EOF
  if [ "`wc  $filebase$i  | awk '{print $1}'`" = "1" ]; then
    cat << EOF >>$output
NO SEL LOG - is the node working?
EOF
  elif [ "`wc  $filebase$i  | awk '{print $1}'`" = "2" ]; then
    tail -1 $filebase$i >>$output
  else
    cat $filebase$i | $IPMI_DIR/L440GX.py >>$output
  fi
cat << EOF >>$output
</pre>
<hr>
EOF
done

######################################################################################Q

cat <<EOF >>$output
<h1><center>$gang Cluster SEL Write Done : `date`</center><h1>
<hr>
</body>
EOF

