#!/usr/bin/csh
#(ie run the cshell on this)

#This file is executable shell script based on tailmail (ref below) re-written to allow sourcing of http mbox file on a
#distant machine
#matching keyword for top of file changed to set phrase used in this example = "^Holmes Bulletin"
#output to file "last_bulletin.txt" used for creation of webtext
#the previous day's bulletin is moved to file "nlast_bulletin.txt"
#Two files are created to allow for view of Yesterday, today, tomorrow bulletin, depending on 

#version 1.0 2004 Sept 19

#K.C. McFarland HJH PTA web guy
#www.dcn.davis.ca.us/go/hjh/

# version = 1.06 of tailmail 2002 Feb 15
# 2002 Feb 15, 1.00: origin 
 
# extract the last mail from the mbox

# documentation:
# http://www.lecb.ncifcrf.gov/~toms/tailmail.html

# Dr. Thomas D. Schneider
# National Cancer Institute
# Laboratory of Experimental and Computational Biology
# Frederick, Maryland  21702-1201
# toms@ncifcrf.gov
# permanent email: toms@alum.mit.edu
# http://www.lecb.ncifcrf.gov/~toms/

#default arguments if nothing specific in usage
#usage: tailmail [number] [target file]
#set target1 = http://velocipede.dcn.davis.ca.us/pipermail/hjhbulletin.mbox/hjhbulletin.mbox

set number = 1


#set local folder locations for system executables
#set grep = /usr/local/bin/grep
#set grep = /usr/bin/grep
#set sed = /usr/bin/sed
#set lynx = /usr/local/bin/lynx
#set lynx = /usr/bin/lynx

#choose line number to print from top of document--finds all matching line numbers, then last of all
#test of set line
#set line = `lynx -source http://velocipede.dcn.davis.ca.us/pipermail/hjhbulletin.mbox/hjhbulletin.mbox | grep -n "^Holmes Bulletin" |tail -1|head -1|tr ":" "\012"|head -1`
set line = `/usr/local/bin/lynx -source http://velocipede.dcn.davis.ca.us/pipermail/hjhbulletin.mbox/hjhbulletin.mbox | grep -n "^Holmes Bulletin" |tail -$number|head -1|tr ":" "\012"|head -1`
#print the mbox last message to file last_bulletin with <br> on each line
#(/usr/local/bin/lynx -source http://velocipede.dcn.davis.ca.us/pipermail/hjhbulletin.mbox/hjhbulletin.mbox | tail +1000 | sed 's/^/\<br\>/g' >! /home/wheel/hjh/public_html/administration/bulletin/last_bulletin.txt ) >>& /home/wheel/hjh/public_html/administration/bulletin/error.out
(/usr/local/bin/lynx -source http://velocipede.dcn.davis.ca.us/pipermail/hjhbulletin.mbox/hjhbulletin.mbox | tail +$line | sed 's/^/\<br\>/g' >! /home/wheel/hjh/public_html/administration/bulletin/last_bulletin0.txt ) >>& /home/wheel/hjh/public_html/administration/bulletin/error.out
/usr/bin/cmp -s /home/wheel/hjh/public_html/administration/bulletin/last_bulletin0.txt /home/wheel/hjh/public_html/administration/bulletin/last_bulletin.txt
#/usr/bin/echo $?
#if (! 0 = $?) then
#	/usr/bin/mv -f /home/wheel/hjh/public_html/administration/bulletin/last_bulletin.txt /home/wheel/hjh/public_html/administration/bulletin/nlast_bulletin.txt
#	/usr/bin/mv -f /home/wheel/hjh/public_html/administration/bulletin/last_bulletin0.txt /home/wheel/hjh/public_html/administration/bulletin/last_bulletin.txt
#endif

