How to pass password and prompt user for IP address while doing ssh and scp?

Hi All,

I want to copy /.ssh/OM.pub file from source to destination.
Here source IP address, username and password is always fixed.
Whereas destination server IP address, password always gets changed.

From destination server :-
I am trying to write a script in which it should log in to source without asking for password (as it is fixed).
And get the file and put in destination server

Below credentials are for source server
username = root
password = shroot

#!/bin/sh

echo "%%%%%%I am at destination server%%%%%%%%"
echo "%%%%%% log in to source %%%%%%%"
ssh root@10.34.80.53 (here how to pass "shroot" automatically in script)
scp ~/.ssh/id_rsa.pub root@ASK_USER_FOR_DESTINATION_SERVER_IP:/tmp/id_rsa.pub
exit

echo "%%%%%%I am at destination server%%%%%%%%"
cat /tmp/id_rsa.pub >> ~/.ssh/authorized_keys;rm /tmp/id_rsa.pub; chmod 0600 ~/.ssh/

Regards,
Madhur

If ftp is enabled on the source server, try this ftp

I am not aware of anything clean to send password via ssh other than expect.

--ahamed

If you have Expect available, this will work:

#!/usr/bin/expect -f
#
# send a single file via scp
#
#

# check command-line for correct number of
# arguments
if {[llength $argv] != 3} {
    puts stderr "Usage: sendfile </path/to/file> <host> <remote directory>"
    exit 1
}

# store argument
set f [lindex $argv 0]
set h [lindex $argv 1]
set d [lindex $argv 2]

# set credentials
set u "root"
set p "shroot"

# send the file to the given host
spawn scp $f $u@$h:$d

# handle the password prompt
expect "?assword:*"
send -- "$p\r"
send -- "\r"

# done
expect eof

c536622c3315ac7f830107200232a62f

FYI... a .netrc file is the traditional means to automate login into ftp servers. Ftp as well as the use of .netrc files are not recommended.