- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Script to Archive Files more than 7 Days Old
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
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
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
09-18-2000 07:53 AM
09-18-2000 07:53 AM
Does anyone have a canned script that can accomplish the task?
Thanks.
John Felgendreger
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2000 08:01 AM
09-18-2000 08:01 AM
Re: Shell Script to Archive Files more than 7 Days Old
cd
find . -mtime +6 -exec mv {}
Will move files 7 days old and older.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2000 08:02 AM
09-18-2000 08:02 AM
Re: Shell Script to Archive Files more than 7 Days Old
You can use:
# cd /mydirectory
# find . -mtime +7 | cpio -pdxm /myarchive
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2000 08:14 AM
09-18-2000 08:14 AM
Solution#!/bin/sh
# Assumptions: 1. that you already have the files created SIA*
# 2. That this script will be run once a week (eg. from the cron)
#
BASE_DIR=/archive
SOURCE_DIR=/source
NUMERIC_DATE=`date +%Y%m%d`
DAY_OF_WEEK=`date +%u`
DAY_TO_RUN=7 # Set day to run to Sunday, ie. run this only on Sundays
# BASE_DIR is the base archive directory ( change to whatever you want your archive files to be stored in )
# SOURCE_DIR is where your files SIA* are found.
if [ $DAY_OF_WEEK -ne $DAY_TO_RUN ] ; then
if [ ! -d $BASE_DIR/$NUMERIC_DATE ] ; then
mkdir $BASE_DIR/$NUMERIC_DATE # if archive directory for this week does not exist then
# create it
fi
find $SOURCE -name "SIA*" -mtime +6 -exec mv {} $BASE_DIR/$NUMERIC_DATE/ \;
# look for all files with starting with the name SIA that are older than 6 days
# and move them to the corresponding directory
else
echo " Sorry nothing to do today - this has been set to run only on the $DAY_TO_RUN day"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2000 08:16 AM
09-18-2000 08:16 AM
Re: Shell Script to Archive Files more than 7 Days Old
I might add that if you are interested in preserving the last access times of the files in question, add the -a option to the cpio. Thus:
# cd /mydirectory
# find . -mtime +7 | cpio -padxm /myarchive
...JRF...