1753556 Members
5685 Online
108796 Solutions
New Discussion юеВ

scp and expect script

 
Karthik_sg
Frequent Advisor

scp and expect script

hi how do u do scp with expect script.
for ex: my remote machine ip is 201.33.4.22
and i have file named log in /tmp directory.

And the below is my script .but it seems to have an error can any 1 help me out.thnks in advance.

#!/usr/bin/expect

log_user 0

set my_passphrase "passphrase"
set my_password "hithr"

spawn "/usr/bin/scp" "root@201.33.4.22:/tmp/logstatus2 /wys_new/log"


while {1} {
expect {
"root@201.33.4.22's password:" {
send "$my_password\n"
}
# -re "(#|\\\$|%) $" {
# log_user 1
# send_user "Shell prompt found. Dropping to shell:"
send "\n"
log_user 1
break
}
}
}
interact
4 REPLIES 4
paolo barila
Valued Contributor

Re: scp and expect script

Hi,
you can configure a publickey authentication with a null passphrase:

login IDA@SERVER1

SERVER1# ssh-keygen -t rsa -C "ssh_for_`whoami`@`hostname`" -f ~/.ssh/id_rsa
empty for no passphrase



SERVER1# cp -p id_rsa.pub authorized_keys.SERVER1
SERVER1# chmod 600 auth*
SERVER1# scp -p authorized_keys.SERVER1 SERVER2:/$PWD


login IDB@SERVER2

SERVER2# cat authorized_keys.SERVER1 >> authorized_keys
SERVER2# chmod 600 authorized_keys

IDA@SERVER1

SERVER1# ssh IDB@SERVER2
yes

(and viceversa)

Pablo
share share share
Karthik_sg
Frequent Advisor

Re: scp and expect script

hi ,if i understand this properly,ur trying to explain the key from my machine and polave it in the remote machine.And by doing this the need of expect script will no longer be needed right.c the problem is this in the remote machine scp has been disabled meaning the port is closed and for all the reasons the remote key is not responding to any keys,which now leaves me only one way to go and therefore i asked the above script question.
Anybody willing to share the ideas are welcomed and tell me whts wrong with the above script
paolo barila
Valued Contributor

Re: scp and expect script

expect can automate scripts that manually works
share share share
larstr
Advisor

Re: scp and expect script

You should really listen to Pablo here. Using public key authentication would help you alot as you wouldn't need to supply the credentials upon every login.

There's also no need to open a new thread on this topic all the time.

Lars