counter is not local to this loop - it should be explicitly used in the loop not somewhere else, because it is controlling the loop. If you need to, move
. config_main inside the loop as well, it does not break anything.
Code:
while [ $counter -lt 5 ]
do
getfile
sleep 2
let counter=$counter+1
done