- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Deleting files oler than 20 minutes
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
Forums
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
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
тАО02-09-2009 09:36 PM
тАО02-09-2009 09:36 PM
On my database server, archives are created in a file system very frequently and i move those archives to another file system so that this file system doesn't get full. My current job moves all archives to the other file system but some times it corrupts my archives because it also moves the archive currently being written and has not finished yet, so the solution in my mind is to move only archive files older than, let say 15 minutes so i will be sure that only finished archives are being moved to the other file system. Can anyone tell me how to edit my current script to accomplish this. Please see my script.
##########################################
date
for fstr in `find /odsdata1/archive/ods_* -type f -print`
do
echo "Moving $fstr"
mv $fstr /odsarchive2/backup/ods/archive/
done
date
echo "End of transfer"
######################################
Thanks
Salman
Solved! Go to Solution.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 10:00 PM
тАО02-09-2009 10:00 PM
Re: Deleting files oler than 20 minutes
# perl -MFile::Find -le 'find(sub{print $File::Find::name if -f $_ && -M _ <= 1/24},@ARGV)' /path
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 10:03 PM - edited тАО09-04-2011 04:13 AM
тАО02-09-2009 10:03 PM - edited тАО09-04-2011 04:13 AM
Re: Deleting files older than 20 minutes
You'll need to create a reference file with touch for 20 minutes ago. (Or use gnu find, -mmin +20.)
The problem with 20 minutes ago is that you need to do date arithmetic on touch. If now is 16:00, then the reference file would be:
touch 02091540 ref_file
You can also solve the reference file issue by creating it manually the first time then just use your sleep or cron to remember 20 minutes ago:
touch ref_file_new # for next time
for fstr in $(find /odsdata1/archive/ods_* -type f ! -newer ref_file); do
done
mv ref_file_new ref_file
sleep $(( 20 * 60 ))
I suppose you could put the touch at the bottom if the find and mv doesn't take too long.
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 10:18 PM
тАО02-09-2009 10:18 PM
Re: Deleting files oler than 20 minutes
Thanks for your reply. I would be rather interested in, "find -mmin" command. Can you please edit my script to add this portion. If you think that i can't achieve 20 mins, you can make it 1 hour.
Thanks in advance
Salman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2009 12:40 AM
тАО02-10-2009 12:40 AM
SolutionExample script:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=131801
How to overcome issues that may come up in such a script:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1227620
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2009 04:29 AM - edited тАО09-04-2011 04:13 AM
тАО02-10-2009 04:29 AM - edited тАО09-04-2011 04:13 AM
Re: Deleting files older than 20 minutes
>"find -mmin" command. Can you please edit my script to add this portion?
Unless you install GNU find, you can't. HP-UX's find only has the standard day granularity with -mtime. If you don't want to use GNU, you will have to use a reference file or use ahsan's perl solution.
>you can make it 1 hour.
That is still 1/24 too small. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2009 04:45 AM
тАО02-10-2009 04:45 AM
Re: Deleting files oler than 20 minutes
To find your candidates, use Perl like this (sorry Ahsan, you can't just copy and paste previous solutions):
# perl -MFile::Find -le '@ARGV=(".") unless @ARGV;find(sub{print $File::Find::name if -f $_ && -M _ >= 1/96},@ARGV)' /path
You can pass multiple /path arguments if you like. RUnning without any argument ('/path') infers the current directory.
The "1/96" is "1/96" of one day or one 15-miunute period of age.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2009 05:22 AM
тАО02-10-2009 05:22 AM
Re: Deleting files oler than 20 minutes
Actually, it is just as easy to do everything in one Perl script:
# cat ./mymover
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use File::Copy;
my $dstdir='/odsarchive2/backup/ods/archive';
@ARGV = (".") unless @ARGV;
print STDERR "Begin @ ", scalar localtime, "\n";
find(
sub {
if ( -f $_ && -M _ >= 1 / 96 ) {
print STDERR "Moving '$_'\n";
move( $File::Find::name, $dstdir ) or die "$!\n";
}
},
@ARGV
);
print STDERR "Ended @ ", scalar localtime, "\n";
1;
...Again, pass the source directory name or "." or nothing at all to denote the current working directory for the source path.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2009 05:41 AM - edited тАО09-04-2011 04:14 AM
тАО02-10-2009 05:41 AM - edited тАО09-04-2011 04:14 AM
Re: Deleting files older than 20 minutes
>JRF: The "1/96" is one 15-minute period
You might want to use an expression so you don't have to explain it:
15 / (24 * 60)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2009 05:56 AM
тАО02-10-2009 05:56 AM
Re: Deleting files oler than 20 minutes
> Dennis: You might want to use an expression so you don't have to explain it:
15 / (24 * 60)
Yes, I agree, in this case that would be good. So change:
if ( -f $_ && -M _ >= 1 / 96 ) {
...to:
if ( -f $_ && -M _ >= ( 15 / ( 24 * 60 ) ) ) {
...which makes the 15-minute interval much clearer and allows leveraging further:
...
my $age=15
@ARGV = (".") unless @ARGV;
...
if ( -f $_ && -M _ >= ( $age / ( 24 * 60 ) ) ) {
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2009 10:30 PM
тАО02-10-2009 10:30 PM
Re: Deleting files oler than 20 minutes
all the above solution are fine for your problem, but you have to be sure tht the log file you are trying to move is not really in use by the database.
I suggest you to include in your script some Oracle command to shiwtch the log file in use (in sorry but now I don't rememeber those). IN this way you are sure that file older than 'x' min is really not in use.
Just my .02$.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2009 11:26 PM
тАО02-10-2009 11:26 PM
Re: Deleting files oler than 20 minutes
just wanted to leave you the zsh line for what you need:
ls -ltr **/*(.mm+15)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2009 11:27 PM
тАО02-10-2009 11:27 PM
Re: Deleting files oler than 20 minutes
If files, dirs and subdirs then:
rm -Rf **/*(.mm+15)
If only files:
rm -f *(.mm+15)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2009 09:57 AM
тАО02-16-2009 09:57 AM
Re: Deleting files oler than 20 minutes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2009 10:13 AM
тАО02-16-2009 10:13 AM
Re: Deleting files oler than 20 minutes
> OldShool: I saw "move", but the above deletes.....
Well, not mine, the code even says "move" :-))
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2009 10:49 AM
тАО02-16-2009 10:49 AM
Re: Deleting files oler than 20 minutes
or, as one of the other posters noted, force oracle to switch archives. in such a case, build the list first, switch the file, then process everything in the list
- Tags:
- fuser