利用expect实现自动交互ssh/scp 发表于 2021-08-20 更新于 2023-05-05 自动ssh123456789101112#!/usr/bin/expectset host 192.168.10.210set user protest2set password 1qazXDR%set port 22spawn ssh $user@$host -p $portexpect {"(yes/no)?" { send "yes\r";exp_continue }"*assword:*" { send "$password\r" }}interact 自动scp123456789#!/usr/bin/expectset password 1qazXDR%spawn scp /tmp/1.txt protest2@192.168.10.210:/tmp/expect { "(yes/no)?" { send "yes\n";exp_continue} "*assword:" { send "$password\n" }}expect "100%"expect eof