The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sync files from two different servers. madan1 Shell Programming and Scripting 2 03-10-2009 12:50 PM
Need to calculate sftp time beteen two servers. koulvivek UNIX for Dummies Questions & Answers 2 12-10-2008 01:28 PM
Unable to scp/sftp between two servers DeCoTwc UNIX for Dummies Questions & Answers 1 09-12-2008 04:11 PM
SFTP Transfer Across Multiple Servers Cameron Shell Programming and Scripting 0 05-20-2008 10:08 AM
need script to connect sftp servers kittusri9 Shell Programming and Scripting 1 05-10-2008 06:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-08-2009
vharsha vharsha is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 6
SFTP files to two servers

Hi,

I need to write a unix shell script which sends files to a server1 from my server via sftp. Then it needs to again SFTP files from that server1 to another server2. And finally remove the transferred files in the intermediate server1. Please provide me pointers on how to achieve the same. All are unix flavored servers.

Your inputs are greatly appreciated.
Thanks in advance.
  #2 (permalink)  
Old 05-09-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 740
I would suggest using scp with password-less SSH setup in preference to sftp for automated transfers.

For the first server you could have a cron job running a script every few minutes or so that simply copys the files to server1 and then moves those files out of the way so they don't get sent again, something like:
Code:
scp -pr * server1:/server1directory
mv * ../donedirectory
Then on Server1 do a cron job calling a script that SCPs one file at a time and if successful deletes the local copy of the file, something like:
Code:
ls -laR > listfile
while read FILE; do
  scp ${FILE} server2:/server2directory 2>&1 > /tmp/scp_log_file
  RESULT=$?
  SCPTEST=`egrep -i "error|fail|denied|illegal|no such|error|unexpected|unknown|too long|lost connection" /tmp/scp_log_file`
  if [ ${RESULT} -eq 0 -a -z "${SCPTEST}" ]; then
    rm ${FILE}
  else
    echo "Error: ${FILE} not sent to server2."
  fi
done < listfile
  #3 (permalink)  
Old 05-10-2009
vharsha vharsha is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 6
Thanks Tony.

The requirement is that I should not run a cron job from the server1 (intermediate server). But what I am thinking to do is that I shall login using scp on server2 in my second script from my local server and will fetch the data via ftp from server1 using the commands suggested by you. Please let me know whether this approach will work. Thanks again for your help.
  #4 (permalink)  
Old 05-10-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 740
Yes you can run a script on sever2 instead of on server1, ftp would allow you to delete the files from server1 once copied onto server2 whereas scping would require a separate ssh session to delete the files from server1.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0