#!/usr/bin/expect
set timeout 10
set username [lindex $argv0]
set passwd [lindex $argv1]
set hostname [lindex $argv2]
spawn ssh $username@$hostname
expect "*password:"
send "passwd\r"
interact
本文介绍了一个使用Expect脚本实现SSH自动登录的例子。该脚本通过传递用户名、密码和主机名作为参数来实现远程登录操作。首先设置超时时间,然后定义变量存储登录所需的各项信息,并使用spawn命令启动SSH会话。
#!/usr/bin/expect
set timeout 10
set username [lindex $argv0]
set passwd [lindex $argv1]
set hostname [lindex $argv2]
spawn ssh $username@$hostname
expect "*password:"
send "passwd\r"
interact
795

被折叠的 条评论
为什么被折叠?