#! /bin/tcsh -f # # see how long the beamline has not been used # # # set up to monitor the DCSS3.0 server log set logfile = /data/log/watchdog.log set filter = '/ stog_note image_ready/{print $NF}' set lastframe = "" set lastframetime = "" if (`uname` == "SunOS") then # use this for LBL/DCS log file set logfile = /prod/DCS/log/hwserv.log set filter = '/img/{print $NF}' set burnhost = bl821k2 which tclsh8.2 >! /dev/null if(! $status) alias tclsh tclsh8.2 which tclsh8.3 >! /dev/null if(! $status) alias tclsh tclsh8.3 alias awk nawk endif set tempfile = tempfile if($?XFORMSTATUSFILE) then if(-e $XFORMSTATUSFILE) then set lastframe = `awk '/.img$/{print $NF}' $XFORMSTATUSFILE` set lastframetime = `echo $XFORMSTATUSFILE | awk '{print "puts [file mtime "$NF"]"}' | tail -1 | tclsh` endif endif if ( "$lastframe" == "" ) then set lastframe = `tac $logfile | awk "$filter" | head -1` endif if ( "$lastframe" == "" ) then set lastframe = `awk "$filter" $logfile | tail -1` endif if( "$lastframetime" == "" ) then set lastframetime = `echo "$lastframe" | awk '{print "puts [file mtime "$NF"]"}' | tail -1 | tclsh` endif if ("$lastframetime" == "") then set lastframetime = `tac $logfile | awk '/image_ready/{printf "%d\n", $7}' | head -1` endif set lastframedate = `echo "$lastframetime" | awk '{print "puts [clock format "$1"]"}' | tclsh` # compute beam time that has been "wasted" set beamtime_since_lastframe = "" set year = `echo "puts [clock format $lastframetime -format %Y]" | tclsh` set month = `echo "puts [clock format $lastframetime -format %B]" | tclsh` set date = `echo "puts [clock format $lastframetime -format %m-%d-%Y]" | tclsh` ring.com if($status && -e "/data/log/beamline/${year}/${month}/$date Data.txt") then cat "/data/log/beamline/${year}/${month}/$date Data.txt" |\ awk 'NF==24{printf "set date [clock scan \"%s %s %s\"];",$1,$2,$3;\ printf "puts \"[clock format $date] $date ";\ $1=$2=$3="" ; print $4,$5,$6, "\""}' |\ tclsh |\ awk '$8<100 && last>100{print $7} {last=$8} END{if($8>100) print $7}' |\ cat >! ${tempfile}down.log set last_beam = `tail -1 ${tempfile}down.log` rm -f ${tempfile}down.log set beamtime_since_lastframe = `echo $lastframetime $last_beam | awk '$1+0<$2+0{print $2-$1}'` endif # see if there is trouble in collection set framestat = `tail -50000 $logfile | awk '/completed collectFrame/{print $NF}' | tail -1` set now = `echo puts [clock seconds] | tclsh` @ idle = ( $now - $lastframetime ) echo $idle | awk '{printf "%02d:%02d:%02d ", $1/3600, ($1/60)%60, $1%60}' echo "$lastframe $lastframedate" echo $beamtime_since_lastframe | awk '{printf "%02d:%02d:%02d wasted time\n", $1/3600, ($1/60)%60, $1%60}' if("$framestat" != "normal" && "$framestat" != "") then if("$framestat" == "") set framestat = "unknown status" echo "WARNING: last collection exited with: $framestat" endif