I'm trying to send special characters (password) which contains #?!k;|C
.
The password is dynamic and cannot be hardcoded in the script, so I'm passing it as variable as shown below
$ expect ./passwordlessSSH.exp $hostname "$password"
the code of this script is as below
#!/usr/bin/expect -f
set host [lindex $argv 0]
set pass [lindex $argv 1]
spawn ssh-copy-id -i /home/hdpsvcs/.ssh/id_rsa.pub hdpsvcs@$host
expect {
"yes" {
send "yes\r"
}
"assword" {
send "$pass \r"
}
exit 0
But still it is not running the script properly. I don't see any error but the variable is not passed correctly. The output is as shown below:
$ expect ./passwordlessSSH.exp $hostname "$password"
spawn ssh-copy-id -i /home/hdpsvcs/.ssh/id_rsa.pub test@otesthost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:
"/home/test/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
\S
Kernel \r on an \m
test@test's password:
$
"$pass\r"
without a space, not"$pass \r"
. Also, add a short sleep before the send to allow the remote script to switch off echo (and flush the tty).exit 0
tointeract
so you can remain logged in.