help with if condition

I do have a situation where , i need to zip the log files in the directory when the file exceeds more than 10MB.

cd $ORACLE_HOME/network/log
find . -type f -name "listener_*.log" >  listeners

Now i have all my *.log files listed in the listeners file

So now i need to find the size of each log file listed in the listeners file which exceeds more than 10mb

and zip it..

Could you please me , i'm really stuck here.

Naveen.

Hi.

If your find has the -size option you could save yourself a step (the option is standard, but it's operands may vary).

     -size n[ckMGTP]
             True if the file's size, rounded up, in 512-byte blocks is n.  If n is followed by a c, then the primary
             is true if the file's size is n bytes (characters).  Similarly if n is followed by a scale indicator then
             the file's size is compared to n scaled as:

             k       kilobytes (1024 bytes)
             M       megabytes (1024 kilobytes)
             G       gigabytes (1024 megabytes)
             T       terabytes (1024 gigabytes)
             P       petabytes (1024 terabytes)

find . -type f -name "listener_*.log" -size +10M | xargs gzip

Thanks for that !!!

I will be having multiple listeners_*.log in a directory , so i need to check each individual log .

Could you please help me

It's probably a good idea to ensure that your listener isn't running when you compress the file.

Why do you need to check each one? Check it for what?

yes .. you are currect ... we have a multiple listeners and multiple logfiles on each ORACLE_HOME

suppose i do have

listener_hhh.log
listener_yyy.log

I need to check each size of the listener and

execute the following steps

cp listener_xx.log listener_xx.log.old
cat /dev/null > listener_xx.log
Basicall i need to have loop to check the each listener log with the size

Something like:

find . -type f -name "listener_*.log" -size +10M | while read FILE; do
  cp "$FILE" "$FILE.old"
  gzip "$FILE.old"
  > $FILE
done