LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-25-2008, 11:44 AM   #1
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Rep: Reputation: 15
Question Is this possible (file archiving/tidying script)


ok i want to make a script that a cronjob will activate at 0600 hours every day (4 hours before a sutdown -h now saves the server from the major heat of the sun )
what i want it to do is ;
scan a specific folder and all the subfolders
move any folders and files that are over 45days old to a different hard drive (which is mounted as drive2 in my users folder)
it needs to preserve the filing structure (so for example say /data/bills/edf.pdf was 46days old it would move the folder to /drive2/data/bills/edf.pdf)
if it finds empty folders it needs to delete them
i then want it to scan the second hard drive for any files over 200 days old and delete them (thats a scary bit cos if i do that wrong all of my files go bye bye!)

im thinking this is possible but i have no idea where to even begin!
 
Old 07-25-2008, 12:52 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
'find' allows you to use different timespecs: mtime, atime, ctime: see 'man find' to get the idea, practice a bit. 'cp' allows you to preserve filestructure as would a 'tar|untar' combo or cpio. A directory being empty means 'test' and with simple globbing you can use the exit code to determine to delete it or not. If all of this sounds a bit too much then you want some basic shell scripting docs like http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html and http://www.tldp.org/LDP/Bash-Beginne...tml/index.html and if you feel up to it maybe even start with the http://www.tldp.org/LDP/abs/html/ ...
 
Old 07-25-2008, 01:15 PM   #3
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by unSpawn View Post
'find' allows you to use different timespecs: mtime, atime, ctime: see 'man find' to get the idea, practice a bit. 'cp' allows you to preserve filestructure as would a 'tar|untar' combo or cpio. A directory being empty means 'test' and with simple globbing you can use the exit code to determine to delete it or not. If all of this sounds a bit too much then you want some basic shell scripting docs like http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html and http://www.tldp.org/LDP/Bash-Beginne...tml/index.html and if you feel up to it maybe even start with the http://www.tldp.org/LDP/abs/html/ ...
im thinking some sort of masters degree may be needed lol
will look into it all
i was thinking along the lines of;

find * timestamp>45days if so move /drive2/*

bugger
 
Old 07-25-2008, 01:25 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Quote:
Originally Posted by mrgreaper View Post
im thinking some sort of masters degree may be needed lol
No, not at all. But if you make yourself *think* it's difficult before even trying then you'll make it harder.


Quote:
Originally Posted by mrgreaper View Post
find * timestamp>45days if so move /drive2/*
Yes, almost there...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tidying up my boot menu Steve W Linux - Newbie 9 08-07-2007 04:41 AM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 11:37 PM
Create a script to display file name, Inode, and size of any file. Has to be a script JaxsunApex Linux - Newbie 7 01-29-2007 09:15 PM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 12:00 PM
Monthly Archiving Script... help with "date" & "cron" Supp0rtLinux Linux - Software 3 01-03-2003 10:29 PM


All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration