script for Copying files from one server to another using scp

Hi Scripting experts,

I am new to the unix scripting. Please help me out for solving the condition given below

I am trying to develop a script for Copying files which are getting generated in server A to server B using scp. In serverA files are generating as for eg abc1.txt, abc2.txt, abc3.txt.... . I need to append these file contents to a single file in ServerB. Whenever new files are getting generated in the ServerA those file content details need to be appended at the end of the single file in serverB.

Looking forward to hear from you alll

THanking you in anticipation

Rohith G
rohithji@gmail.com

I can give you clues, on how to do.

  1. Look for new files creation in ServerA.
    [ Modules available in Perl to do that ].

  2. Concatenate the files newly created to ServerB using cat command, in ssh command option.

There can be better ways to accomplish this..

I'd use this way.

I would concatenate the info in a temporal file in server A, when you consider that the file is finished. you send with scp to server B .... and delete the file in server A.

I think , thats not the info you are looking for. In pseudo_code:

while (exit condition) {
if {new file created} { # test with ls output
cat new_file >> temporal_file
} else {
do nothing
}
scp ./temporal_file user@serverB:/path
rm temporal_file

You could try something like:

cat abc[0-9]*.txt | ssh serverb "cat >> path-to-singlefile"

Hi Trutoman,

Thanks for your reply . I find this logic as a good one. since i m new to scripting can you please explain me in little bit more detail mannner on how to perform this

Regards,

Rohith G

If you cant transform pseudocode in code you may consider move this post to Newbies Forum. You are supposed to code that script in this forum....or thats what i think. If dont Scrutinizer has code to you another way to do it.