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 ...
- 09-10-2009 #1Just 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
- 09-11-2009 #2
If you use ssh instead of scp, you could something like this on server A:
The quotes pass the command line, including the redirection operator to serverB. The remote cat command copies stdin since no files were specified.Code:cat abc*.txt | ssh serverB 'cat > combined.txt'
- 09-11-2009 #3Just 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
- 09-11-2009 #4Just Joined!
- Join Date
- Dec 2007
- Location
- Bangalore >> India
- Posts
- 28
Thanks,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>
----------------------------------------
Computer And Technologies
- 09-11-2009 #5Just 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
- 09-13-2009 #6Just 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
- 09-16-2009 #7Linux 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.
- 09-16-2009 #8Just 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


Reply With Quote
