[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Linux script to copy files from host to host

Posted on 2013-12-17
3
Medium Priority
?
333 Views
Last Modified: 2013-12-18
I am using RHEL 6.4

Regarding an earlier post where I discovered that I could run a remote script from my host as follows:

putty -t user@host -pw password -m local_commands_file

Open in new window


I want to write a script that will either:

1> Copy a file from the calling machine to the remote machine

2> Copy a file from one remote machine to another

How can I do this ?

Thanks
0
Comment
Question by:Los Angeles1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 39724878
I strongly assume that you can't install pscp (?), which would make things quite easy.

(1) Moreover, your first requirement cannot be satisfied, because we have different operating systems, so we need a compatible file transfer, like FTP or the mentioned scp (over ssh). PuTTY alone cannot do this.

2) Copying between remote Linux hosts is possible, but please be aware that ssh/scp on Unix/Linux do not allow specifying a password on the command line.

Anyway:

On your Windows machine putty to the host where you want to copy from (host1) like this:

putty -t user@host1 -pw password -m local_commands_file

and let "local_commands_file" contain

scp /source_file_spec user@host2:/target_spec

where host2 is the machine you want to copy to.

Please note again, you must have set up passwordless (public key) authentication between the machines host1 and host2, otherwise you will be prompted for a password.

wmp
0
 

Expert Comment

by:gilesb2002
ID: 39727830
Below is an example of how I do this with and expect script. We have a server that process large amount of files. The script below copies files from several different locations to that server for processing.

The script copies a file passed to it from the command line from a remote server to the local server. You can change the scp command to move the to and from wherever you want.

The file does contain the password in plain text so make sure it only has the necessary read/write permissions. Also you will have to manually ssh into the remote servers from where the script is ran before the script will work. This is so that you can accept the RSA key from the remote server. You could modify the script to send back yes when prompted if you wanted.

#!/usr/bin/expect -f

# Expect script to supply root/admin password for remote ssh server 
# and execute command.

# set Variables
set filetoget [lrange $argv 0 0] 

set username <your user>
set password <your users password>

# remote IP address
set ipaddr <IP address of remote server>
set timeout -1
   
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn scp $username@$ipaddr:/$filetoget /<destination>/
match_max 100000

# Look for passwod prompt
expect "*?assword:*"

# Send password aka $password 
send -- "$password\r"

# send blank line (\r) to make sure we get back to gui
send -- "\r"

expect eof

Open in new window

0
 

Author Closing Comment

by:Los Angeles1
ID: 39727939
The scp solved many a problem.  

Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question