通过expect实现自动输入密码
#!/usr/bin/expect spawn ssh root@192.168.61.223 expect "password:" send "123456\r" interact
expect是用于处理交互,通过它可以完成自动化交互. expect包含set,send,expect,spawn,interact命令.
- set - 设置参数
- send - 用于向进程发送字符串
- expect - 从进程接收特定格式字符串(支持通配符)
- spawn - 启动新的进程
- interact - 允许用户交互
当然如果要通过传参方式把密码传入,则可以使用$argv
来实现
set pwd [lindex $argv 0] send "$pwd\r"
PS: 获取第一个参数