cherry2891 cherry2891 - 1 year ago 107
Bash Question

Send password when using scp to copy files from one server to another

using scp to copy files from 1 unix server to another regularly and performing certain actions. to do this quickly I wish to use a unix script which does the scp and inputs the password required to complete the scp.

I have tried the expect command to send the password throught the unix command line however unable to achieve this so far.

sample commands

scp ./abc.txt hostname/abc.txt
expect "*password:*"
send "mypassword\r"

I get these errors:

couldn't read file "password: ": no such file or directory[5]: send: not found [No such file or directory]

am I missing something?

Answer Source

Here is how I resolved it.

It is not the most secure way however it solved my problem as security was not an issue on internal servers.

Create a new file say password.txt and store the password for the server where the file will be pasted. Save this to a location on the host server.

scp -W location/password.txt copy_file_location paste_file_location


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download