If the seach did not yield any results it should then seach inside the second latest sub folder till it reaches the oldest sub folder or if it finds the string.
Just the same way as on Unix.
afaik, both are POSIX compilant, and as long you use the same shell, it is, beside folder locations (simple speaking), 100% identical.
Scripting per-se, doesnt change beween unix, linux or bsd.
After more than 375 posts, I am very disappointed that you still don't have any idea how to write a simple for or while loop using a standard shell! And, the title of this thread doesn't give any indication of what you are trying to do.
You were also very skimpy with details about whether or not all of your directories will actually contain a log file for the desired hostname, how the variables hostname , fdrdate , and greptime are set, nor where the log directory is located.
Maybe the following will give you a starting point:
#!/bin/ksh
#set -xv
basedir="/path/of/log"
fdrdate_new=${1:-fdrdate_new default value}
greptime=${2:-greptime default value}
hostname=${1:-default hostname}
looking=1
cd "$basedir"
ls -td * | while [ "$looking" ] && read fn
do
if [ ! -d "$fn" ]
then continue
fi
if grep "$greptime.*exit" "$fn/Prod.$hostname.log" | grep "$fdrdate_new"
then echo "Match found in file: $fn/Prod.$hostname.log"
looking=
else echo "No match found in file: $fn/Prod.$hostname.log"
fi
done
if [ "$looking" ]
then echo "No match found."
exit 1
fi