scripting headache... loops & variables

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

Next time, please put your code within the code tags.

Try this.

#! /bin/sh

LOGDIR=/usr/local/tibco/adapters/DAAC/bin/archive/
TEMPDIR=/usr/local/tibco/adapters/DAAC/bin/archive/temp/

> "$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

while read DAACFILE 
do 
{
   while read line
   do
   IP=$(echo $line | awk '{ print $7 }')

   grep "$IP" "$DAYLOG$DAACFILE" | grep tracking >> $TEMPDIR/gettrack;
   awk '{print $15}' $TEMPDIR/gettrack | sed -e "s_tracking=_grep \"_" -e "s/zzw\#/\" $DAACFILE \| grep \"MSISDN :\"/" >> TEMPDIR/getMSISDN.sh; 
   awk '{print $1, $2, $3, $4, $5, $6, $12, $13}' "TEMPDIR/getMSISDN.sh"  >> $TEMPDIR/MSISDN.out
   done < "$TEMPDIR/extract22.EST.txt"
}
done < "$TEMPDIR/list_files"

Now getting `IP=$' unexpected

Is the code you've given me specific to a shell type or OS ??

Thanks

What is the first line in your script ? Is it something like #! /bin/sh.

yep, I tried /bin/sh, /bin/ksh and /bin/bash none of which worked :frowning: (all had same error)

I have tried another method, and believe I have it working. I'll post what I've done once I know it's worked.

Thanks for the help.

Replace $(...) with `...`

` are the backticks.