- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Remove audit 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
Forums
Discussions
Discussions
Forums
Discussions
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
08-07-2002 11:12 AM
08-07-2002 11:12 AM
I have a directory /user1/audit which has hundreds of files in it with names like "01-Aug-2002", "12-Dec-2001", and "13-Jun-2000". We only need to keep the files that are less than 31 days old. Is there a command to remove these files?
TIA, Derek
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2002 11:14 AM
08-07-2002 11:14 AM
Re: Remove audit files
find /user1/audit -type f -mtime +30 -exec rm {} \;
I would first try this command with a safe command like -exec echo {} \; before doing the real thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2002 11:18 AM
08-07-2002 11:18 AM
Re: Remove audit files
I forget to add before anybody does a find -mtime that I can't use find because the file "12-Dec-2001" might not have been created on December 12, 2001. I know it's dumb but I didn't write the software. I actually need to figure out how old a file is based on the name of the file.
TIA, Derek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2002 11:36 AM
08-07-2002 11:36 AM
SolutionThis should be very close:
#!/usr/bin/sh
DIRNAME=/user1/audit
MAX_DAYS=30
cd ${DIRNAME}
TODAY=$(caljd.sh)
for F in $(ls)
do
if [[ -f ${F} ]]
then
echo "File: ${F}\t\c"
AGE=$((${TODAY} - $(caljd.sh -e -i -S "-" -c ${F})))
echo "Age: ${AGE} days\c"
if [[ ${AGE} -gt ${MAX_DAYS} ]]
then
echo "\tRemove\c"
# rm ${F}
fi
echo
fi
done
You can invoke caljd.sh -u for full usage. Make sure that you use Version 2.1; earlier versions could not handle dates with names of months.
Here is caljd.sh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2002 11:41 AM
08-07-2002 11:41 AM
Re: Remove audit files
Note that I commented out the actual rm command. After you are satified with the results, you can uncomment the command.
Attached is caljd.pl.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2002 12:05 PM
08-07-2002 12:05 PM
Re: Remove audit files
Thanks again, Derek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2002 12:09 PM
08-07-2002 12:09 PM
Re: Remove audit files
Before you turn this into a cronjob, you need to make sure that caljd.sh is in the PATH and exported. I would do this explicitly in the script. Cron has an intentionally sparse environment. I would also remove all the echo commands or add a command line option for verbose if you want to keep them in.
Regards, Clay