- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Deleting old files (logs or other files)
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
тАО12-09-2004 10:21 AM
тАО12-09-2004 10:21 AM
I have used the following command to delete files:
find /psft/pt8.42/dev/appserv/prcs/DEV_2/log_output -name '*CUPOFOCB*' -type d -mtime +5 -exec rm {} \;
However this removes files that are 5 days or older. I have a process that generates a log file every minute. I am trying to use the integer in a decimal form like -mtime +0.5 but it does not work.
Can you please help me device a script that will do this for the fraction of a day?
Thanks in advance.
-Pankaj Mandalia
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-09-2004 10:38 AM
тАО12-09-2004 10:38 AM
Re: Deleting old files (logs or other files)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-09-2004 11:03 AM
тАО12-09-2004 11:03 AM
Re: Deleting old files (logs or other files)
THank you for the suggestion and reply... The reason I used d was for a directory and I tried rmdir {} also but that did not make any difference. I will try the -newer approach and let you know the results.
Thank you.
-Pankaj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-09-2004 09:50 PM
тАО12-09-2004 09:50 PM
SolutionHere's a small example of using a reference file:
touch -t YYYYMMDDhhmm /tmp/ref_file
myhost# date
Fri Dec 10 11:39:54 MET 2004
myhost# pwd
/tmp
myhost# ll tor*
-rw------- 1 root sys 6562 Nov 2 18:05 tor
-rw-r--r-- 1 root sys 0 Dec 10 11:37 tor2
myhost# touch -t 200412010000 ref_file
myhost# ll ref_file
-rw-r--r-- 1 root sys 0 Dec 1 00:00 ref_file
myhost# find /tmp ! -newer /tmp/ref_file -type f -name "tor*" -exec ll {} \;
-rw------- 1 root sys 6562 Nov 2 18:05 /tmp/tor
myhost#
In the example you can see that I have two files that matches the name specification. One that is older than the reference file.
Since -newer normally would seelct the newest file - I must negate (use ! ) to get the oldest one.
It is also important to stack the find options in proper order. Therefore I first look for old files, then search for proper type (ordinary file), then a matching filename.
Removing directories:
Your rmdir command probably failed because there where files in the directory.
If you would delete an entire directory structure which contain files you should use the command:
find "your options" -type d -exec rm -r {} \;
rm -r will recursively remove all files + directory
Be careful with this and do as Clay tells - test it first some times with an ls command.
Best regards
Tor-Arne
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-14-2004 08:43 PM
тАО12-14-2004 08:43 PM
Re: Deleting old files (logs or other files)
Here is an example how to send ITO alarm
if file is older than n seconds:
## Perl script that tells the "age" of the file in seconds
$FILE = $ARGV[0]; ##Filename
$DIFF = $ARGV[1]; ##Accepted time (seconds) of last modification
$TODAY = time();
$WRITE_SECS = (stat($FILE))[9];
$AGE = $TODAY - $WRITE_SECS;
$AGE_MIN = $AGE/60;
if ( $AGE > $DIFF ) {
printf "Alarm! %s is %d min old\n",scalar $FILE, $AGE_MIN;
`$ENV{OPCMSG} sev=warning appl=OS msg_grp=OpC object=opcmsg msg_text="Check fil
e $FILE. Last change $AGE_MIN minutes ago"`;
}