#!/bin/sh
echo "Content-type: text/csv\n"
# set environment variables.
. /u/catcom/catcom_vars
###################################
#echo "
"
#echo "Process QUERY_STRING=$QUERY_STRING"
#echo ""
#for qtok in `echo "$QUERY_STRING" | tr "&" " "`
#do
# echo "qtok=[$qtok]"
# eval $qtok
#done
###################################
# set working dir
#rjs cd /u/catcom/t21web/webdirenq
###################################
# get lock
LOCKFILE="/tmp/t21websql.lok"
while true
do
if [ ! -f "$LOCKFILE" ]; then
break;
fi
sleep 2
done
touch $LOCKFILE
###################################
tmpfile1="/tmp/webdirtmp$$.unl"
rm -f $tmpfile1
#rjs
#runisql </dev/null 2>&1
#database catcom;
#unload to "$tmpfile1" DELIMITER ","
#select dt.recordno, dc.surname, dc.firstname, dc.title, dc.tieline, dt.extension, dc.mobile, dc.telephone, dc.department, dc.location1, dc.email
#from directtemplate dt, directcustom dc
#where dt.recordno = dc.recordno
# and dc.listd2 = "Y" and dc.listmobiled2 = "Y"
#union
#select dt.recordno, dc.surname, dc.firstname, dc.title, dc.tieline, dt.extension, "", dc.telephone, dc.department, dc.location1, dc.email
#from directtemplate dt, directcustom dc
#where dt.recordno = dc.recordno
# and dc.listd2 = "Y" and dc.listmobiled2 = "N"
#order by 2, 3
#SQLCMD0
#rjs
tmpfile1="KFT02_tmp.unl"
echo "RecordNo,Surname,Firstname,Title,Tie,Extension,Mobile,Telephone,Department,Location,Email"
cat $tmpfile1 | sed -e 's/,$//'
#rjs
#rm -f $tmpfile1
###############################
# hit file
hitsfile="hits"
touch $hitsfile
hits=`cat $hitsfile`
if [ -z "$hits" ]; then
hits="0"
fi
hits=`expr $hits + 1`
echo "$hits" > $hitsfile
echo "99999,HITS,$hits,,,,,,,,"
###############################
# remove lock
rm -f $LOCKFILE
###############################
exit 0