LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-22-2008, 10:20 AM   #1
sir-lancealot
Member
 
Registered: Aug 2007
Posts: 336

Rep: Reputation: 31
Non programmer looking for push...


ok, I do know my web skills (cf, php, etc.) but not on the shell side. Bsaically I have a nightly backup that get's pulled from our co-lo locally. Each start of the new month I take the 1st of the month, move it to a monthly folder for archiving and remove the rest. I would like to automate this as there are 200+ files, but looking for how/where to start.

The file name strucuture is, server.backup.yyyymmdd.tar.gz. I can't simply say find *01* as it will screw up stating January, so if anyone can say yea, just do this one or 2 lines, or say, look at these commands I can start on this.

Thanks as always.
 
Old 09-22-2008, 10:49 AM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 31
Assuming that years always take 4 digits, months always take 2 digits, and days always take 2 digits:
Code:
 ls <directory to search> | grep -E ".*[0-9]{4}[0-9]{2}01.*"
or
ls <directory to search> | grep "01.tar.gz"
That should give you a list of the files you want. You can store them in a variable from there and then loop over them to move them to the directory you want.

You could create a script that takes a directory path (destination) as input and then moves all the files you want and removes all others.
 
Old 09-22-2008, 12:50 PM   #3
sir-lancealot
Member
 
Registered: Aug 2007
Posts: 336

Original Poster
Rep: Reputation: 31
Perfect, I started with a shell script 101, and after the "hello world" I knew it would be a while.

Thanks much.
 
Old 09-22-2008, 06:50 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
With a name format like that, they will sort naturally, so at the start or end of the mth, use

ls|sort

server.backup.20080101.tar.gz
server.backup.20080102.tar.gz

So to get the first use

ls|sort|head -1

last:

ls|sort|tail -1


PS these might help:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

Last edited by chrism01; 09-22-2008 at 06:51 PM.
 
  


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
Obex Push thoyyib Linux - Software 2 05-10-2006 08:12 AM
Programmer to Programmer ( Long Story Of A GUI ) mdoubledragon Programming 1 10-13-2005 05:41 PM
Push installation balpeck Linux - Networking 1 09-21-2003 09:30 AM


All times are GMT -5. The time now is 06:12 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration