Help with script to transfer files from one server to another

Hi

I have the following script:

#!/bin/sh
set -x
touch -mt 201210040000 /tmp/ref1
touch -mt 201210042359 /tmp/ref2
find /fs1/bscsrtx/BSCS_ix/WORK/LOG -type f \( -newer /tmp/ref1 -a ! -newer /tmp/ref2 \) > file_lst
scp $(< file_lst) root@10.100.48.76:/ano2005/fs1_2015/LOG/

but somehow its giving me the following error:

+ touch -mt 201210040000 /tmp/ref1
+ touch -mt 201210042359 /tmp/ref2
+ find /fs1/bscsrtx/BSCS_ix/WORK/LOG -type f ( -newer /tmp/ref1 -a ! -newer /tmp/ref2 )
+ 1> file_lst
find: cannot stat /fs1/bscsrtx/BSCS_ix/WORK/LOG
+ 0< file_lst
+ scp root@10.100.48.76:/ano2005/fs1_2015/LOG/
Usage: scp [options] [[user@]host1:]file1 [...] [[user@]host2:]file2

Pls can I have help on this

Looks like find is complaining that directory

/fs1/bscsrtx/BSCS_ix/WORK/LOG

does not exist.

Please confirm.

Regards
Peasant.

in the source:

#pwd
/fs1/bscsrtx/BSCS_iX/WORK/LOG

in the destination:

 pwd
/ano2005/fs1_2015/LOG

There is a difference in the provided output and script..

/fs1/bscsrtx/BSCS_ix/WORK/LOG
/fs1/bscsrtx/BSCS_iX/WORK/LOG

The devil is in the details.

Regards
Peasant.

1 Like

yes there was a typing mistake, but now its only sending one file,as opposed to more that 100 files in that directory:

#./transf
+ touch -mt 201210040000 /tmp/ref1
+ touch -mt 201210042359 /tmp/ref2
+ find /fs1/bscsrtx/BSCS_iX/WORK/LOG -type f ( -newer /tmp/ref1 -a ! -newer /tmp/ref2 )
+ 1> file_lst
+ 0< file_lst
+ scp /fs1/bscsrtx/BSCS_iX/WORK/LOG/13853006.log root@10.100.48.76:/ano2005/fs1_2015/LOG/
Password:
13853006.log                                                                                                                100% 3280     3.2KB/s   3.2KB/s   00:00

Is the content of the file_lst populated with 100 of files ?

Check the content of the file and verify that.
Be sure to examine the output of scp, you might hit ARG_MAX limit with this kind of action on that number of files.

Regards
Peasant.

you are right, there is onely 1 file inside

/tmp/fr/file_lst

!!
but I�ve used the markers

/tmp/fr/ref1

and

/tmp/fr/ref2

with a timestamp....

---------- Post updated at 02:24 PM ---------- Previous update was at 02:13 PM ----------

its now working fine, I have decreased the markers

touch -mt 201210040000 /tmp/ref1
touch -mt 201210092359 /tmp/ref2

One query:

After transferring, how can I delete the transferred files in the source server.
Does a simple

rm $(< file_lst)

will work?

Yes you may delete like that.
But, using such redirections can be a security issue if someone writes some path in file_lst before you issue rm command.

Handle with care or rewrite the script with additional checks (like checksuming the file_lst after find and before rm to be sure the content has not changed and making sure you issue the rm command in right directory.)

Regards
Peasant.

1 Like