Script for moving one file with date content in name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for moving one file with date content in name
# 1  
Old 05-13-2013
Script for moving one file with date content in name

Dear All,

I am having a database that generates daily backup files in the below format.

Code:
abc_date_0010.zip

.

Can you please suggest a method to copy the last day's file to another location.

I am trying with if statement, but having difficulty while I use the condition like

Code:
if [ -e "abc_`date -d'yesterday' '+%Y%m%d'`_0010.zip" ]; then

Any luck !!

Last edited by Scrutinizer; 05-15-2013 at 03:12 AM.. Reason: code tags
# 2  
Old 05-13-2013
What is the difficulty? Appears to be correct. What error are you seeing?

For clarity, you may put the date in a separate variable and then use it in the condition:
Code:
dt=`date -d 'yesterday' +%Y%m%d`
if [ -e "abc_${dt}_0010.zip" ]; then

Also, debug your script using the set -x option and see where the script fails.
# 3  
Old 05-14-2013
Thanks balajesuri for the reply

while I am running the script, it got stuck at below point.

after that its not going further. Rest of my script is below


Code:
then

scp abc_20130513_0010.zip remoteserver:/tmp > /dev/null;

OUT=$?;
if [ $OUT = 0 ];then
rm -rf abc_20130513_0010.zip;
fi
fi

I am getting below response after using set -x
Code:
++ date -d yesterday +%Y%m%d
+ date=20130513
+ '[' -e abc_20130513_0010.zip ']'

Please correct me if something is missing.

Thanks in advance

Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by skooby; 05-14-2013 at 08:16 AM.. Reason: code tags
# 4  
Old 05-15-2013
set -x option is just to expand the commands and show what's happening on the console output. There seems to be nothing wrong with your output. Is your script doing what its meant to do?
# 5  
Old 05-15-2013
Nope, actually my intention was to check the backup file is there and if its generated then, copy this daily backup file to one of the remote server and once the copying is completed, remove the file. Now after the if statement, its not proceeding to
Code:
scp abc_20130513_0010.zip remoteserver:/tmp > /dev/null;

OUT=$?;
if [ $OUT = 0 ];then
rm -rf abc_20130513_0010.zip;

Also not generating any error.
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

2. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

3. UNIX for Dummies Questions & Answers

Script moving files based on date

Hi, I need a script that moves files based on date to a folder. The folder should be created based on file date. Example is : Date file name ----- -------- Oct 08 07:39 10112012_073952.xls Oct 09 07:39 10112012_073952.xls Oct 10 07:39 ... (6 Replies)
Discussion started by: rockingvj
6 Replies

4. Shell Programming and Scripting

Grep the Content of a LOG File which has latest Date and Time

Hi All, Need a small help. I have a log file which keeps updating for every Minute with multiple number of lines. I just want to grep few properties which has latest Date and Time to it. How do i do it? I wanted to grep a property by name "Reloading cache with a maximum of" from the... (4 Replies)
Discussion started by: nvindraneel
4 Replies

5. Shell Programming and Scripting

Sort content of text file based on date?

I now have a 230,000+ lines long text file formatted in segments like this: Is there a way to sort this file to have everything in chronological order, based on the date and time in the text? In this example, I would like the result to be: (19 Replies)
Discussion started by: KidCactus
19 Replies

6. Shell Programming and Scripting

Moving Content from one file to another with variables

Greetings All, Need some help, your input is appreciated. Scenario: I have five files, each has one line with comletely different content. I execute the command to combine all the five lines of content into a single file. Goal: I would like to take that single file that has the... (3 Replies)
Discussion started by: royarellano
3 Replies

7. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

8. Shell Programming and Scripting

modifying date (-10 hours) in the content of a file

Dear Experts, I have a problem. I have a file which has contents such as below, with about 500K lines 34|1|532|2008.10.24 23:41:13|2-1-1-13|90130060128441171|CO0402|0|0x00000201A402000021F6005D4901EC1C2000|0|0|0xE00319FFFFBFFFFE| with field separator "|", the 4th field is the date (date... (3 Replies)
Discussion started by: aismann
3 Replies

9. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

10. Shell Programming and Scripting

file moving based on file content

Hi All my scenario is as follows... I have the following three files in directory alphabet, containing the respective character string... Filename Character String alphabet01.dat AAA alphabet02.dat BBB alphabet03.dat CCC based on... (12 Replies)
Discussion started by: melvyn.cochrane
12 Replies
Login or Register to Ask a Question