Saturday, May 16, 2009

Solaris: Shell script to write output to a file

HiI need to run a sql query each day which retrieves data based on a numerical incremental (MAXID) value. I want then to store the max value from last query ran in a file (tempid) and then use this new number each day to retreive only the new data. Attached is a sample of the script being used.

#!/bin/sh

echo "Retrieve id"

FILE="/tmp/tempid"
MAXID=0

if [ ! -f $FILE ]; then
echo "$FILE : deos not exist"
exit 1
elif [ ! -r $FILE ]; then
echo "$FILE : can not read"
exit 2
fi

# read $FILE using the file descriptors
exec 3<&0 #save standard input
exec 0<$FILE
while read line
do

MAXID=$line

done

#
# Query
#

sh -c "sqlplus etc ................ <

spool /tmp/temp.csv

No comments:

Post a Comment

About

Blogger templates