#!/bin/ksh # # $Id: shellscript-l,v 1.1 2007/07/29 21:01:24 vogelke Exp $ # # NAME: # shellscript-l # # DESCRIPTION: # "shellscript-l" will accept a mail message from that list # on stdin, and store it in a timestamped file. # # AUTHOR: # Karl Vogel # Sumaria Systems, Inc. PATH=/bin:/usr/bin:/usr/local/bin export PATH trap 'exit 1' ERR myname=`basename $0` die () { echo "$*" >& 2 exit 1 } top="/doc/html/htdocs/$myname" test -d "$top" || mkdir $top test -d "$top" || die "$top not found" cd $top tmp="./tmp" test -d "$tmp" || mkdir $tmp test -d "$tmp" || die "$tmp under $top not found" # store message safely new=`safecat $tmp .` # get the message date in a usable format # example: gdate -d 'Sun, 29 Jul 2007 06:02:18 -0400' "+%Y %m%d.htm" # 2007 0729.htm date=`formail -xDate: < $new` set X `gdate -d "$date" "+%Y %m%d.htm"` shift yr=$1 dest="$yr/$2" test -d "$yr" || mkdir $yr test -d "$yr" || die "`pwd`: unable to mkdir $yr" # store message body only in date file sed -n -e '//,/<.html/p' < $new > $dest && rm $new host=`hostname` echo "http://$host/$myname/$dest" | mailx -s "$myname for $date" vogelke@$host exit 0