It just does the break...even though the files are not the same...
# Compare extracts
#==========================================
count=0
while (( count < 5 ))
do
(( count+=1 ))
echo "Try $count"
file1=$(ls -l /tmp/psjava.xml| awk '{print $1,$2}')
file2=$(ls -l /tmp/dbextract.txt| awk '{print $1,$2}')
if (( count >= 5 ))
then
echo "Too many retries"
echo "Please check source why the files dont match "
exit 1
fi
if [ "$file1" != "$file2" ]
then
echo "File1 and File2 don't match. I will sleep 30 seconds and try again. 5 tries is my limit."
sleep 30
else
echo "File1 and File2 match."
break
fi
done
> touch a b
> ls -l
total 16
drwxr-xr-x 2 me mygroup 256 Jul 24 17:03 .
drwxr-xr-x 29 me mygroup 4096 Jul 24 17:02 ..
-rwx------ 1 me mygroup 735 Jul 24 17:03 Test
-rw-r--r-- 1 me mygroup 0 Jul 24 17:03 a
-rw-r--r-- 1 me mygroup 0 Jul 24 17:03 b
> ./Test
Try 1
File1 and File2 match.
> ln a c
> ls -l
total 16
drwxr-xr-x 2 me mygroup 256 Jul 24 17:03 .
drwxr-xr-x 29 me mygroup 4096 Jul 24 17:02 ..
-rwx------ 1 me mygroup 735 Jul 24 17:03 T
-rw-r--r-- 2 me mygroup 0 Jul 24 17:03 a
-rw-r--r-- 1 me mygroup 0 Jul 24 17:03 b
-rw-r--r-- 2 me mygroup 0 Jul 24 17:03 c
> ./Test
Try 1
File1 and File2 don't match. I will sleep 30 seconds and try again. 5 tries is my limit.
>
In any case $9 gives the filenames not $8, and why do two ls's on two different files and expect the filename to be t he same? (unless your name's freddie :))
In any case on top of that the script works for me in ksh (not clear which shell he is using).
Not with every version of ls, probably it's more safe to use $NF assuming the OP doesn't have names with spaces.
With this version:
ls --version
ls (GNU coreutils) 5.97
I get this output:
$ ls -l
total 12
-rw-r--r-- 1 users franklin 336 2009-03-24 15:44 az
-rw-r--r-- 1 users franklin 336 2009-03-24 15:44 bz
-rwxr-xr-x 1 users franklin 651 2009-03-24 16:13 inplace.awk