Not sure if it's possible but I'm trying to break out of an if statement that's in a while loop. I do not want to exit the while loop though. I tried using exit and break but both exit the while loop. The problem is that I don't know which folder the file I'm looking for is which is why I want to exit the current if statement when I match the searched file so that I can move on to the next serial number.
I have a txt file called 'drives-fw-sn.txt' that contains a list of serial numbers. Breakdown of code:
- I read in one serial number at a time from drives-fw-sn.txt while a while loop
- I search for a file called output_log using find
- I then print the first occurrence of the serial number from the found file
- Next I print that the log has been found and want
Here's a snippet of my code (there are more than 3 test folders). Note that it still contains the exit commands which exit the while loop.
while read node; do
if find ./test1/*log* -maxdepth 2 -type f -name output_log -exec egrep -m 1 $node {} \; ; then
echo "Log SN $node available"
exit
fi
if find ./test2/*log* -maxdepth 2 -type f -name output_log -exec egrep -m 1 $node {} \; ; then
echo "Log SN $node available"
exit
fi
if find ./test3/*log* -maxdepth 2 -type f -name output_log -exec egrep -m 1 $node {} \; ; then
echo "Log SN $node available"
exit
fi
done < drives-fw-sn.txt
Aucun commentaire:
Enregistrer un commentaire