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.

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

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

Any luck !!

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:

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.

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

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

++ date -d yesterday +%Y%m%d
+ date=20130513
+ '[' -e abc_20130513_0010.zip ']'

Please correct me if something is missing.

Thanks in advance

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?

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

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