macOS:
xbrew install expect
x
set user "用户名"
set host "IP 或域名"
set password "密码"
spawn ssh $user@$host
expect {
"yes/no" {
send "yes\r"; exp_continue
}
"password: " {
send "${password}\r"
}
"]#" {
}
}
interact
注意:
- 第一行指定的脚本解释器是 expect,不是 sh 或 bash
xxxxxxxxxx
chmod +x <脚本文件路径>
执行脚本即可,比如:
xxxxxxxxxx
./login_xxx.sh