#!/usr/bin/expect -f set host [lindex $argv 0] set user [lindex $argv 1] set password [lindex $argv 2] spawn ssh-copy-id -i /home/$user/.ssh/id_ecdsa.pub $host expect { "continue" { send "yes\n"; exp_continue } "assword:" { send "$password\n"; } "added: 1" { exit 0 } "added: 0" { exit 1 } }