Operating System - HP-UX
1825805 Members
2268 Online
109687 Solutions
New Discussion

move history file to another directory

 
dopril
New Member

move history file to another directory

Hi,
I am newbie in unix/linux command. I have a system that every day always generate file on directory /mysystem/history. I want to create automatically job that can move files on directory /mysystem/history that created 7 days ago to directory /mysystem/oldhistory.
But i dont know how to do that. Any one can help me ?
3 REPLIES 3
Patrick Wallek
Honored Contributor

Re: move history file to another directory

You would need to write a script that utilizes the 'find' command to search for files within a directory and then takes action on those files.

# man find

for more details.

Now if you want this script to run automatically you will need to set it up in cron.

# man cron
# man crontab

for more details.

Have a read thru the man pages (they are a system administrators best friend!) and post back if you still have questions.
V.Tamilvanan
Honored Contributor

Re: move history file to another directory


Hi,

Put this line as a shell script and run by cron everyday. This script move files which is older than 7 days from /mysystem/history directory to /tmp/history directory.

#find /mysystem/history -type f -mtime +7 -exec /usr/bin/mv {} /tmp/history \;

Bharat Katkar
Honored Contributor

Re: move history file to another directory

Create Shell script for e.g. myscript with following commands:
#!/usr/bin/sh
touch /mysystem/oldhistory
cat /mysystem/history >> /mysystem/oldhistory
> /mysystem/history

Make the script executable using
#chmod +x myscript

Then edit crontab file:
# crontab -e
insert entry as follows:
1 1 * * 5

Save it
This will execute the sript every Friday at 1 hour 1 min.
You can change the execution as per your convenience by changing first two field ( 1st Min .. 2nd Hour )

Hope this should work for you

You need to know a lot to actually know how little you know