Mac 记住ssh用户名密码的expect 脚本

进入Mac用户目录:

$cd /usr/bin

创建item2login.sh文件,内容如下:

#!/usr/bin/expect

set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
        "(yes/no)?"
        {send "yes\n";exp_continue}
        "password:"
        {send "[lindex $argv 3]\n"}
}
interact

最后执行:

item2login.sh 22 root 192.168.1.188 root

    脚本                     端口号 用户名 服务器地址         密码 要一一对应

猜你喜欢

转载自jatter.iteye.com/blog/2326425