UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 8th, 2011, 01:30 PM
fred2028 fred2028 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 142 fred2028 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 32 m 7 sec
Reputation Power: 7
Automating move/compress commands

Hey everyone. I'm relatively new to Unix but know many of the commands from using Ubuntu. If I want to automatically move files into folders and compress others, how would I achieve this?

Basically, some files get dropped into say /fred/ everyday. At the end of the day, I'd like to take all of those files and put it into a folder in say /archive/1 day ago/ and move all of the files from /archive/1 day ago/ to /archive/2 days ago/. Then the stuff in /archive/2 days ago/ would be compressed into say /archive/2011-09-08.zip and placed in /archive/.

How would I accomplish this? Any code, code fractions, or pointers in where I can learn would be very appreciated.
__________________
Cheers,
Fred Liu

Reply With Quote
  #2  
Old September 8th, 2011, 02:04 PM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,111 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 7 h 43 m 38 sec
Reputation Power: 1485
First things first, you may have got the order in which you wish to do that wrong ...!
Zip up oldest archive and remove those files
Move day 1 stuff to day 2
Move current to day 1

Having spaces in the directory names may be an issue, so take care with those.
At the relevent time (maybe via cron?) have the 'archive process' fire off:
Code:
arch_date=$(date "+%F")
zip -q /archive/${arch_date} "/archive/2 days ago"
zip_cc=$?
if [ $zip_cc -ne 0 ]
then
  echo "Zip error (code $zip_cc)"
  exit 1
fi
rm "/archive/2 days/ago/*"
rm_cc=$?
if [ $zip_cc -ne 0 ]
then
  echo "rm error (code $rm_cc)"
  exit 1
fi
mv "/archive/1 day ago/*" "/archive/2 days/ago/"
mv_cc=$?
if [ $mv_cc -ne 0 ]
then
  echo "mv error from 1 day ago (code $mv_cc)"
  exit 1
fi

mv "/fred/*" "/archive/1 day ago/"
mv_cc=$?
if [ $mv_cc -ne 0 ]
then
  echo "mv error from fred (code $mv_cc)"
  exit 1
fi

Not tested and, as always, before implementing anything that deletes/moves stuff about be very sure you have a working backup and that the things being deleted and moved have been identified correctly!
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Automating move/compress commands

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap