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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to Zip the files from date Stamp to end date Stamp redlotus72 UNIX for Dummies Questions & Answers 1 12-08-2006 03:29 PM
creating a new file with date stamp mgirinath Shell Programming and Scripting 2 02-28-2006 09:00 AM
Inserting Date&Time Stamp In Existing Log File shephardfamily UNIX for Dummies Questions & Answers 3 02-24-2006 01:01 AM
ftp copy: preserve source file date stamp cassj UNIX for Dummies Questions & Answers 5 02-16-2005 03:38 PM
File date and time stamp Xenon UNIX for Dummies Questions & Answers 1 10-09-2001 12:58 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-07-2006
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
Date Stamp on new file

Dear Gurus,

I'm trying to move a number of files from one directory to another directory with a new date stamp. This is my script:

#! /bin/csh

Today_Date=`date +%Y%M%D`
mv /usr/TRS/data/TS* /usr/TRS/backup/TS*.${Today_Date}

when i run the script i'm getting the following errors:

mv: /usr/TRS/backup/TS*.20062309/08/06 not found

Any advise?

Thanks

wee
Reply With Quote
Forum Sponsor
  #2  
Old 09-07-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
what is the date format that u want exactly ?

date +%Y%M%D

%M - minute format

is of the format

YYYYMMMM/DD/YY

YYYYMMDD
try this,

Code:
date +%Y%m%d
Reply With Quote
  #3  
Old 09-07-2006
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
hi thanks for the help. i get the date though (see below), but getting another error message:

mv: /usr/TRS/backup/TS*.20060908 not found

any advise? thanks again.


wee
Reply With Quote
  #4  
Old 09-07-2006
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by lweegp
hi thanks for the help. i get the date though (see below), but getting another error message:

mv: /usr/TRS/backup/TS*.20060908 not found

any advise? thanks again.


wee
i think the destination should not have a '*' ... it should be a valid directory, or a filename.
Reply With Quote
  #5  
Old 09-07-2006
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
Quote:
Originally Posted by ghostdog74
i think the destination should not have a '*' ... it should be a valid directory, or a filename.
thanks. somehow it solved my problem. this is how my script looks like:

#! /bin/sh

Today_Date=`date +%Y%m%d`

mkdir /usr/TRS/backup/${Today_Date}

mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date}

so now i will create today's date as a directory and put all the files in.

the question is how do i remove those directory when they are more than 10 days old? thanks again.
Reply With Quote
  #6  
Old 09-08-2006
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by lweegp
the question is how do i remove those directory when they are more than 10 days old? thanks again.
you can use the find command with -mtime switch. Please do "man find" and see how it is used or you can search the forum
Reply With Quote
  #7  
Old 09-08-2006
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
Quote:
Originally Posted by ghostdog74
you can use the find command with -mtime switch. Please do "man find" and see how it is used or you can search the forum
This is my final script. Do u think it will work? Thanks.

#! /bin/sh

Today_Date=`date +%Y%m%d`

mkdir /usr/TRS/backup/${Today_Date}

mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date}

find /usr/TRS/backup/. -name 'T*' -mtime +1 -exec rm -f {} \;
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0