find and compress…

I have spent a ton of time the last few days at work cleaning up some cron jobs. The standard find, zip, remove log file stuff, but with an interesting twist.

I was happy with:

10 21 * * * find /logs/uswgw -type f -name “app_0*” -mtime +1 -exec nice -19 /bin/compress -f \{\} \;
20 21 * * * find /logs/uswgw -type f -name “trans_0*.Z” -mtime +1 -exec nice -19 /bin/compress -f \{\} \;
30 21 * * * find /logs/uswgw -type f -name “app_0*.Z” -mtime +5 -exec /bin/rm -f \{\} \;
40 21 * * * find /logs/uswgw -type f -name “trans_0*.Z” -mtime +5 -exec /bin/rm -f \{\} \;

I had a more senior coworker do a code review and he almost flipped out of his chair when he looked at my work. He could not believe that I was running multiple finds for both the compress and rm jobs. The cpu cycles I was wasting was too much for him to handle. He recommended I go read up on the “-o” option (or would it be an argument).

Either way, after taking his recommendations into consideration. Here is what was approved after code-review:

10 21 * * * find /logs/uswgw -type f -name “app_0*” -mtime +1 -exec nice -19 /bin/compress -f \{\} \; -o -type f -name “trans*” -mtime +1 -exec nice -19 /bin/compress -f \{\} \;
40 21 * * * find /logs/uswgw -type f -name “app_0*.Z” -mtime +5 -exec /bin/rm -f \{\} \; -o -type f -name “trans_0*.Z” -mtime +5 -exec /bin/rm -f \{\} \;

Am I really gaining that much with the change? Two finds and two execs vs One find and two execs. The math works out. One less process, but is it worth the time? Anybody have any opinions on this?

Leave a Reply