The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File Archive Script KeesH Shell Programming and Scripting 10 06-09-2008 12:11 PM
Script to archive file indira UNIX for Dummies Questions & Answers 0 05-22-2007 11:15 AM
How to transfer files (By using generic script) when using sftp gsri Shell Programming and Scripting 0 08-28-2006 10:39 PM
script to archive all the log files tintedwindow Shell Programming and Scripting 0 06-13-2006 11:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-23-2008
mak1600 mak1600 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 10
Generic Shell Script to Archive a file

Would appreciate if any one can paste a generic schell script to archive a file with date stamp by passing the file with fullpath as parameter

For Eg. /apps/scripts/Archive_File.sh /data_home/project_home/file.txt

this should place the file in the following directory

/data_home/project_home/Archive

Any help is really appreciated...I'm kinda new to KSH and please help me.

Thanks
  #2 (permalink)  
Old 07-23-2008
BMDan BMDan is offline
Registered User
  
 

Join Date: Jul 2008
Location: BlackMesh Managed Hosting
Posts: 66
Not a big ksh person, but how about:

Code:
mv $1 `echo $1 | sed 's/\/[^/][^/]*//'`/Archive/`echo $1 | sed 's/.*\///'`.`date +"%Y-%m-%d"`
N.b. not intended to backup entire directories at a time, but if you do, drop the trailing slash (or just edit the script to do it for you; I wanted to keep it simple).
  #3 (permalink)  
Old 07-23-2008
mak1600 mak1600 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 10
awesome...Thanks a lot for your help...a little bit of refinement...

For some directories it is ARCHIVE, for some archive and for some it is Archive.....How do I include this condition to check for the available archive directory
  #4 (permalink)  
Old 07-23-2008
mak1600 mak1600 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 10
Actually I could not get it to work

here is the error that I get

+ sed s/\/[^/][^/]*//
+ echo test_file.txt
+ sed s/.*\///
+ echo test_file.txt
+ date +%Y-%m-%d
+ mv test_file.txt test_file.txt/ARCHIVE/test_file.txt.2008-07-23
mv: cannot rename test_file.txt to test_file.txt/ARCHIVE/test_file.txt.2008-07-23: Not a directory

File Location /data_home/scripts/test_file.txt
Archive Location /data_home/scripts/ARCHIVE

Thanks for your help
  #5 (permalink)  
Old 07-24-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,322
Try this:

Code:
echo $1|sed 's!\(.*/\)\(.*\)!mv & \1ARCHIVE/\2!' | sh
Before you mv the file be sure you get the expected command with:

Code:
echo $1|sed 's!\(.*/\)\(.*\)!mv & \1ARCHIVE/\2!'
  #6 (permalink)  
Old 07-24-2008
mak1600 mak1600 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 10
It works perfectly...Thanks a lot for your help....
Would like to know if there is a way to see if the check if the directories ARCHIVE/archive/Archive exists and based on that move the files to the Archive directory...since I want to write a generic script that archives the files to archive directory...but for some projects the archive directory is ARCHIVE, for some it is Archive and for others it is Archive.

Once agian thanks for all the help
  #7 (permalink)  
Old 07-25-2008
mak1600 mak1600 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 10
any ideas?
Closed Thread

Bookmarks

Tags
archive, ksh

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0