Item2连接服务器保存信息

1,先写脚本

/Users/wangcheng/item2/login_shell

#  cd /Users/wangcheng/item2/

#  vi login_shell


#!/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

设置可执行权限

# chmod +x login_shell

脚本语法

/Users/wangcheng/item2/login_shell port username ip password