- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Find Command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
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
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- 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
тАО04-04-2011 10:26 AM
тАО04-04-2011 10:26 AM
I can't see if there's a way to do this with find or if I have to resort to something else.
#!/usr/bin/sh
while true
do
find /tmp -name "udapiserver*" ! -newer /tmp/findref -exec rm {} \;
touch /tmp/findref
sleep 3600
done
exit
Solved! Go to Solution.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2011 10:55 AM
тАО04-04-2011 10:55 AM
Re: Find Command
One way is to use a small Perl snippet :
...
WHEN=$(perl -MPOSIX -e 'print strftime "%Y%m%d%H%M\n",localtime(time-(2*60*60))')
touch -amt ${WHEN} /tmp/findref
...
Now, your 'findref' file has a modification timestamp two hours ago (2*60*60 seconds ago) and you can awaken an compare to it as you need.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2011 11:05 AM
тАО04-04-2011 11:05 AM
Re: Find Command
Since you are not asking anything tricky from find (and even if you did), you may want to consider to have a shell or perl script do a glob and look at the date attribute to decide whether a file is a keeper or not.
for example:
$ perl -e 'for () { unlink if -M $_ > 2/24 }'
The -M function returns the age of the file as a floating point value with unit days.
So for 2 hours you want to compare using 2/24
hth,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2011 11:10 AM
тАО04-04-2011 11:10 AM
SolutionBy the way, if you want to avoid poor 'find' performance, use the '+' terminator to the '-exec' argument like:
# find /tmp -type f -name "udapiserver*" ! -newer /tmp/findref -exec rm {} +
This causes multiple arguments to be collected for every 'rm' process spawned instead of forking one 'rm' for every file to be removed.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2011 11:43 AM
тАО04-04-2011 11:43 AM
Re: Find Command
I've incorporated the Perl snippet and the ref file has a timestamp exactly two hours old. I've also taken note of the "+" terminator, I did not know this.
Hein,
I did not try your suggested syntax, but will when I get the chance. Thanks for the response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2011 11:47 AM
тАО04-04-2011 11:47 AM
Re: Find Command
If you don't want to use the perl solution to create the reference files, you'll need to have a sequence of 8 reference files and use and touch the appropriate one each 15 minutes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2011 12:06 PM
тАО04-04-2011 12:06 PM
Re: Find Command
Try a non-destructive version first.
Just after your purge runs, rerun the find, and compare with output from:
perl -e 'for () {$m = -M; print qq($m $_\n) if $m > 2/24 }'
That would just be to get familiar with this method.
for () {...} # walk list, setting $_, executing code block each time
# glob list of filenames matching specification
$m = -M; # store file modification date in varariable $m
print qq($m $_\n) if $m > 2/24 # real work.
hth,
Hein