Surely there's an easier way to do this, lets see if anyone knows! I am new to scripting so go easy on me!
I have the following script and at the moment it doesn't work and I believe the problem is that I am using a while loop within a while loop. When I run the script using sh -x I can see that it is grepping each $DAACFILE but gets no result, so I think $IP has no value set when running this part of the script, which results in the file, gettrack, containg no data... so the result is that MSISDN.out is empty. Any help much appreciated.
LOGDIR=/usr/local/tibco/adapters/DAAC/bin/archive/
TEMPDIR=/usr/local/tibco/adapters/DAAC/bin/archive/temp/
rm $TEMPDIR/getMSISDN.sh
rm $TEMPDIR/MSISDN.out
touch $TEMPDIR/getMSISDN.sh
chmod +x $TEMPDIR/getMSISDN.sh
echo "Enter the month (e.g Jan) you wish to extract MSISDN's for : "
read MONTH
echo "Enter the number of the day (1-31) you wish to extract MSISDN's for : "
read DAY
DAYLOG=$TEMPDIR"$MONTH$DAY"
#CREATES MSISDN.OUT BY COPYING RELEVANT DAYS LOG FILES TO TEMP LOG DIRECTORY, EXTRACTS IP FROM extract??.EST.txt AND GREPS DAAC LOGS FOR MSISDN BASED ON IP ADDRESS AND TRACKINGID.
echo "DMS transactions by MSISDN" > $TEMPDIR/MSISDN.out
ls $DAYLOG > $TEMPDIR/list_files
# exec < $TEMPDIR/list_files
# while read DAACFILE
cat $TEMPDIR/list_files | while read DAACFILE
do
{
#awk '{print $7}' $TEMPDIR/extract$DAY.EST.txt|while read IP
awk '{print $7}' $TEMPDIR/extract22.EST.txt|while read IP
do
# grep $IP $DAYLOG$DAACFILE | grep tracking > $TEMPDIR/gettrack;
grep $IP $DAYLOG$DAACFILE | grep tracking >> $TEMPDIR/gettrack;
awk '{print$15}' $TEMPDIR/gettrack| sed 's/tracking=/grep "/' | sed "s/zzw\#/\" $DAACFILE \| grep \"MSISDN :\"/" >> $TEMPDIR/getMSISDN.sh;
$TEMPDIR/getMSISDN.sh | awk '{print $1, $2, $3, $4, $5, $6, $12, $13}' >> $TEMPDIR/MSISDN.out
done
}
# rmdir $DAYLOG
done