HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find return code ???
Operating System - HP-UX
1825801
Members
2246
Online
109687
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2003 06:40 AM
10-30-2003 06:40 AM
find return code ???
I am using find to check if a file is greater than a specific size, and if it is executing ll to pull off some information:
find ${file} -size +${FINDSZ}c -exec ll {} \; | awk '{printf("%7s %9d %-35s\n",$3,$5,$9)}' >> ${FIND}
Based on if it was greater than the size I was looking for will determine what I need to do next in the script, but I'm not sure how to determine this in the script???
Thanks
find ${file} -size +${FINDSZ}c -exec ll {} \; | awk '{printf("%7s %9d %-35s\n",$3,$5,$9)}' >> ${FIND}
Based on if it was greater than the size I was looking for will determine what I need to do next in the script, but I'm not sure how to determine this in the script???
Thanks
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2003 07:13 AM
10-30-2003 07:13 AM
Re: find return code ???
using $? you always get the return code of the last command executed. in your case that would be awk. by using the pipe you've lost the return code to the find command.
but, if the file your writing to is zero in size before the find and larger then zero afterwards, the find command found some files.
rm $FIND
find ${file} -size +${FINDSZ}c -exec ll {} \; | awk '{printf("%7s %9d %-35s\n",$3,$5,$9)}' >> ${FIND}
if [[ -f $FIND ]] ;then
print "$FIND is created, find found something"
fi
if [[ -s $FIND ]] ;then
print "$FIND exists and is larger then zero"
fi
and your script will run faster if you use xargs
but, if the file your writing to is zero in size before the find and larger then zero afterwards, the find command found some files.
rm $FIND
find ${file} -size +${FINDSZ}c -exec ll {} \; | awk '{printf("%7s %9d %-35s\n",$3,$5,$9)}' >> ${FIND}
if [[ -f $FIND ]] ;then
print "$FIND is created, find found something"
fi
if [[ -s $FIND ]] ;then
print "$FIND exists and is larger then zero"
fi
and your script will run faster if you use xargs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2003 07:18 AM
10-30-2003 07:18 AM
Re: find return code ???
If you mean by return code trhe value of ${?} then find's value is not going to help very much. Assuming you have no syntax errors, it's pretty much always going to be zero whether anything is found or not BUT because this is part of a pipeline it's really awk's value that you will see rather than find's.
Another approach might be to do this:
typeset -L7 USER
typeset -i10 SZ
typeset FNAME
find ${file} -type f -size +${FINDSZ}c -exec ll {} \; | awk '{printf("%7s %9d %-35s\n",$3,$5,$9)}' | while read USER SZ FNAME
do
echo "User = ${USER} SIZE = ${SZ} File = ${FNAME}"
done
Note that now you don't need a temp file.
Another approach might be to do this:
typeset -L7 USER
typeset -i10 SZ
typeset FNAME
find ${file} -type f -size +${FINDSZ}c -exec ll {} \; | awk '{printf("%7s %9d %-35s\n",$3,$5,$9)}' | while read USER SZ FNAME
do
echo "User = ${USER} SIZE = ${SZ} File = ${FNAME}"
done
Note that now you don't need a temp file.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2003 09:38 PM
10-30-2003 09:38 PM
Re: find return code ???
First, when piping commands together, $? will always be the value returned from the last (ie the leftmost) command.
Hoever, unless I've misunderstood, it doesn't look like you need find at all.
Find will find all files from a given directory, but if you know the file name, you can get its size from any of "ls -l", "wc -c", "cksum".
eg
SIZE=$(ls -l ${f} |awk '{print $5}')
if [ $"SIZE -gt YOURMAX ]
then
YOUR CODE HERE to do something with ${f}
fi
If you do need to use find, then enclose the processing within a loop.
You don't need to do any other testing, as you know that find will only return the files you want.
for f in $(find ${file} -size +${FINDSZ}c )
do
YOUR CODE HERE to do something with ${f}
done
-- Graham
Hoever, unless I've misunderstood, it doesn't look like you need find at all.
Find will find all files from a given directory, but if you know the file name, you can get its size from any of "ls -l", "wc -c", "cksum".
eg
SIZE=$(ls -l ${f} |awk '{print $5}')
if [ $"SIZE -gt YOURMAX ]
then
YOUR CODE HERE to do something with ${f}
fi
If you do need to use find, then enclose the processing within a loop.
You don't need to do any other testing, as you know that find will only return the files you want.
for f in $(find ${file} -size +${FINDSZ}c )
do
YOUR CODE HERE to do something with ${f}
done
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP