Find the answer to your Linux question:
Results 1 to 8 of 8
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 ...
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    4

    Unix script for copying files 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

  2. #2
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Location
    Maryland, USA
    Posts
    506
    If you use ssh instead of scp, you could something like this on server A:
    Code:
    cat abc*.txt | ssh serverB 'cat > combined.txt'
    The quotes pass the command line, including the redirection operator to serverB. The remote cat command copies stdin since no files were specified.

  3. #3
    Just Joined!
    Join Date
    Sep 2009
    Posts
    4

    Unix script for copyn files using scp

    Hi,

    Thanks for your reply.

    Is there any way to perform that using scp ? because the requirement is to use scp for that

    Regards,

    RG

  4. #4
    Just Joined!
    Join Date
    Dec 2007
    Location
    Bangalore >> India
    Posts
    28

    Question

    Quote Originally Posted by rohithji View Post
    Hi,

    Thanks for your reply.

    Is there any way to perform that using scp ? because the requirement is to use scp for that

    Regards,

    RG
    cat scp.sh
    #!/bin/sh

    cat abc*.txt &>newabc.txt
    #if u r in Server A
    #ip of Server B:- 127.0.0.1
    scp newabc.txt username@<serverB_IP>:/<path_to_save_file>
    ----------------------------------------
    Thanks,
    Computer And Technologies

  5. #5
    Just Joined!
    Join Date
    Mar 2008
    Location
    Chennai, India
    Posts
    26
    This should work. I am assuming that you know the file to be appended to the current file.

    ------------------------------------------------------------------------------------------
    # Let us say you are on local_server and the other server is
    # remote_server. Run this script from the local_server.
    # temp.txt is a test file. the original file you want to append the
    # information is, let us say target.txt

    #!/bin/sh

    scp new_file.txt@remote_server:<absolute path> temp.txt
    cat temp.txt >> target.txt
    rm temp.txt

    # ">>" is output append redirection operator. this will add new file
    # contents at the end of the file.
    ------------------------------------------------------------------------------------------


    Cheers,
    Sarma

  6. #6
    Just Joined!
    Join Date
    Sep 2009
    Posts
    4

    Scp Script to copy files between servers

    Hi Sarma,

    In the remote server files are creating automatically and we need to copy all the newer files ( hav to keep the script in background) which wil copy all the newer files from remote location to the local server and append it to the file int he local server.

    IS there ny wasys to perform this

    Regards,

    RG

  7. #7
    Linux Enthusiast
    Join Date
    Aug 2006
    Location
    Portsmouth, UK
    Posts
    539
    You'll need to use the "find" command with one of the newer or time switches.

    You might consider "touch"ing a file (to set the time and date) to use as a reference in your script and then using find -cnewer <reference file>

    I'll leave you to ponder, rather than give you a solution
    RHCE #100-015-395
    Please don't PM me with questions as no reply may offend, that's what the forums are for.

  8. #8
    Just Joined!
    Join Date
    Sep 2009
    Posts
    4

    Scp Script to copy files between servers

    Hello everyone ,

    I am able to take files instantly using TRACE option. THanks to everyone for your inputs.

    I have one more doubt regarding how to use password inside scp command. I tried using expect option. but not gettin it done.. now i m using scp by entering the password in the command line. Please help me to find an option to pass the password into the scp command inside the script

    Regards,

    Rohith G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...