Find command issues over while loop or for loops
Hi All,
The below find command returns nothing sometimes , if so it wont even enter into the loop to continue with rest of the code how to handle this ? Appreciated your help ASAP. for file in `find /oracle/admin/XXXXX/udump/bkp/ -type f -size +20M -exec ls -1 {} \;` do if [ ! -f "$file" ] then echo "File \"$file\" does not exist." exit 1 fi proc=`echo $file | awk -F"_" '{print $3}'` active_pid=`ps aux | grep "$proc" | grep -v grep|wc -l` if [ "$active_id" -eq 1 ] then exec "/usr/tools/oracle/Standard/script/DB_Trace_Off.ksh" $INST_NAME $active_pid else gzip $file fi done Regards Bala |
Code:
#!/bin/bash -vx *And since you mentioned the ASAP FLA you will also want to read these: http://mywiki.wooledge.org/ParsingLs http://mywiki.wooledge.orgDontReadLinesWithFor http://mywiki.wooledge.org/UsingFind http://mywiki.wooledge.org/Arguments http://mywiki.wooledge.org/WordSplitting http://mywiki.wooledge.org/Quotes as there's nothing quicker than you reading stuff yourself. |
Quote:
|
If there is something you need to do when the find command doesn't find anything, you could test for that and take the appropriate action, for example:
Code:
#!/bin/bash Code:
tony> ../looptest Code:
tony> ../looptest Code:
tony> ../looptest |
Quote:
Code:
find . | while read -r file |
One More Thing...
Quote:
Code:
tony> ls Code:
tony> find . -type f | while read -r file; do echo "$file"; cat "$file"; rm -v "$file"; done |
As a general rule-of-thumb, in any language or environment, "finders" need to be allowed to "do their own thing, whatever it is, without interruption." If you need to process the list-of-whatevers that they create, then you should plan to "let them generate it, completely, however they want to do it," first, then "iterate through the list that they produced."
|
Try it on a filename that contains a newline character.
|
Quote:
Code:
tony> FILE=`echo -e new'\n'line` |
All times are GMT -5. The time now is 12:32 AM. |