Move the files between Current day & a previous day


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Move the files between Current day & a previous day
# 1  
Move the files between Current day & a previous day

Hi All,

I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day.

i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.

Code:
export BUS_DATE=`cat path/filename.txt| grep 'P_BUS_DATE' | cut -d"=" -f2`
CURR_DY=`date "+%Y%m%d"`
CURR_DY_SECS=`date --date=$CURR_DY +"%s"`
BUS_DATE_SECS=`date --date=$BUS_DATE +"%s"`
DAYS=`$((($CURR_DY_SECS - $BUS_DATE_SECS) / 86400 ))`
echo $DAYS
i=$DAYS
while [ $i -ge 0 ]
  do 
 `mv /patha/filename.$(expr $CURR_DY - $i).dat /pathb/destination/`
  i=$ [ expr $i - 1 ]
done

Pls note the platform is LINUX.

Thanks much in advance,
Freddie

Last edited by methyl; 06-07-2012 at 10:20 AM.. Reason: please use code tags
# 2  
Hi,
may you please show the output of the running script and the output of cat path/filename.txt| grep 'P_BUS_DATE'?
# 3  
Hi Frappa,

Here is the log I am seeing after executing the script.

++ grep P_BUS_DATE
++ cut -d= -f2
+ export BUS_DATE=20120528
+ BUS_DATE=20120528
++ date +%Y%m%d
+ CURR_DY=20120605
++ date --date=20120605 +%s
+ CURR_DY_SECS=1338872400
++ date --date=20120528 +%s
+ BUS_DATE_SECS=1338181200
++ 8
script.ksh: line 31: 8: command not found
+ DAYS=
+ i=
+ '$DAYS'
scripts.ksh: line 33: $DAYS: command not found
+ '[' -ge 0 ']'
scripts.ksh: line 34: [: -ge: unary operator expected

Can you pls shed some light.

Thanks Much
Freddie

---------- Post updated 06-06-12 at 12:28 PM ---------- Previous update was 06-05-12 at 03:52 PM ----------

Hi All,

I made some improvements in the issue below,

Here is the error I am getting now,

Quote:
++ grep P_BUS_DATE
++ cut -d= -f2
+ export BUS_DATE=20120528
+ BUS_DATE=20120528
++ date +%Y%m%d
+ CURR_DY=20120606
++ date --date=20120606 +%s
+ CURR_DY_SECS=1338958800
++ date --date=20120528 +%s
+ BUS_DATE_SECS=1338181200
+ DAYS=9
+ i=9
+ [[ 9 -ge 0 ]]
++ expr 20120606 - 9
+ mv /path/filename.20120597.dat /iis_dev_data/wcc/cpmg/ctl/
mv: cannot stat `/path/filename.20120597.dat': No such file or directory
+ i=8
+ [[ 8 -ge 0 ]]
++ expr 20120606 - 8
+ mv //path/filename.20120598.dat /iis_dev_data/wcc/cpmg/ctl/
mv: cannot stat `/path/filename.20120598.dat': No such file or directory
+ i=7
+ [[ 7 -ge 0 ]]
++ expr 20120606 - 7
Any thoughts are appreciated

Thanks,
Freddie
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #464
Difficulty: Medium
chrony was developed and written in Python.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to save current day files only?

i want to save current day file daily for this is am using below command. cp -p $(ls -lrt | grep "Apr 15" | awk '{print $9}' in order to script this part, i am saving date output in a file using below command date | awk '{print $2,$3}' >>t1 thru below command i want to list the file of... (7 Replies)
Discussion started by: scriptor
7 Replies

2. UNIX for Dummies Questions & Answers

List the files of previous day

I am using KSH. d=date | nawk '{ print $2,$3-1}' ls -lrt SystemOut* | nawk '/d/{print $NF}' I am trying to list the files of previous day but it doesn't seem to be working and i am also not getting an error. result is blank.Need help. (11 Replies)
Discussion started by: vagar11
11 Replies

3. UNIX for Dummies Questions & Answers

current day remote files from FTP

Hi All, I have to work on a korn shell script to pick up only the current day files dropped on the remote server (using ftp). The file do not have daytimestamp on it. It has to be based on server time (AIX) The file naming convention is "test_file.txt" When I log in into the ftp account... (15 Replies)
Discussion started by: pavan_test
15 Replies

4. Shell Programming and Scripting

Command to list current day files only

Hi All, can anyone pls share the command to list the files of current day only. i want to check if there are any files in a particular directory which are not of current date. (6 Replies)
Discussion started by: josephroyal
6 Replies

5. Shell Programming and Scripting

Script to check if last modified day is previous day

Hi, I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it. For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Discussion started by: hegdepras
1 Replies

6. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

7. UNIX for Dummies Questions & Answers

sample script to archive & move previous day syslog files

hi all. Please help me with archiving previous day syslog files. the files have no extension and have the format YYYY-MM-DD. I want to archive the file then move it to some other machine. thanks. (2 Replies)
Discussion started by: coolatt
2 Replies

8. Shell Programming and Scripting

Download previous day files through FTP

Hi All, I have a scenario where I need to download the previous day modified files from other server to my server through FTP . Could any one please send me the shell script for the same. I used the following but I dont know how to proceed after this. ftp -n -i -v $IP <<ENDOFinPUT >>... (3 Replies)
Discussion started by: sarathchandrach
3 Replies

9. Shell Programming and Scripting

delete files one day old in current month only

i want to delete files that are one day old condition is files should be of current month only ie if iam running script on 1 march it should not delete files of 28 feb(29 if leap year :-)} any modifications to find $DIR -type f -atime +1 -exec rm -f{}\; (4 Replies)
Discussion started by: maverick
4 Replies

10. Shell Programming and Scripting

How to compare prev day file to current day file

Hi all: I am new to this board and UNIX programming so please forgive if I don't explain something correctly. I am trying to write a script to keep track of our links, we link one program written for Client A to Client B's directory. What we want to do is to keep track of our linked programs... (1 Reply)
Discussion started by: Smurtzy
1 Replies

Featured Tech Videos