发布于 4年前

Ubuntu16.10 使用 expect 实现 ssh 自动登录

#!/usr/bin/expect -f
# 设置ssh连接用户名
set user root
# 设置ssh连接的host地址
set host host
# 设置ssh连接的port端口号
set port 22
# 设置ssh连接的登录密码
set password password
# 设置ssh连接的超时时间
set timeout -1

spawn ssh $user@$host -p $port
expect "*password:"
# 提交密码
send "$password\r"
# 如果还要操作就按照expect捕捉到窗体展示的信息。
# 根据信息来操作,比如我要更新某个文件的svn然后退出。
# 这里使用zsh所以会输出~
# expect "*~*"
# send "cd /home/shenyifei/myproject && svn up && exit\r"
# 控制权转移
interact
©2020 edoou.com   京ICP备16001874号-3