1753873 Members
7607 Online
108809 Solutions
New Discussion юеВ

Find Command

 
scott5555
New Member

Find Command

I am using the below find command in my code and i am redirecting the output to a file findout in the /tmp folder. I am concerned about the disk space of the tmp folder. It's now having 459 MB free space. I want to check if the output of find command is below 50 MB redirect the output to the findout file in /tmp folder otherwise throw a message "find out exceeded 50 MB limit" How can i do it?
find . -name "R*.ulog.gz" | xargs zgrep -i "SEARCHCONTENT" | cut -f 1 -d ' ' >/tmp/findout
3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: Find Command

>otherwise throw a message "find out exceeded 50 MB limit" How can i do it?

There are no good ways to do this without doing the find twice. Or read it all in memory and stop if too large.
Or put the file elsewhere and then move it to /tmp if < 50 Mb.
Masud Parvez
Valued Contributor

Re: Find Command

You can do it by script

this script might work

nohup find . -name "R*.ulog.gz" | xargs zgrep -i "SEARCHCONTENT" | cut -f 1 -d ' ' >/tmp/findout &
while TRUE=ITRC;
do
SPACE=`du -sk /tmp/findout | awk '{print $1}'`
if [ "51200" -le "$SPACE" ]
then
echo "PROCESS ID $!"
echo "OVER SIZE STOPPING FIND PROCESS"
exit 0
else
echo "SIZE UNDER 50 MB"
fi
sleep 1
done
Deepak Kr
Respected Contributor

Re: Find Command

Single find command will not suffice this requirement.

Dennis is right you have to use find twice.
"There is always some scope for improvement"