在iterm中用expect脚本实现ssh, telnet对aix, linux的自动登录

来源:互联网 发布:舜德数据怎么样 编辑:程序博客网 时间:2024/05/18 01:08

在mac上转战iterm以后,才知道自动登录的内部原理,原来可以用expect脚本做和服务器的自动交互,当然自动登录只是其中的一小部分功能啦


ssh自动登录:

#!/usr/bin/expectset timeout 30spawn ssh [lindex $argv 0]@[lindex $argv 1]expect {        "(yes/no)?"        {send "yes\n";exp_continue}        "password:"        {send "[lindex $argv 2]\n"}}interact

telnet自动登录(适合有些Linux平台,会发送默认用户的情况):

#!/usr/bin/expectset timeout 30spawn telnet -l [lindex $argv 0] [lindex $argv 1]expect {        "assword:"        {send "[lindex $argv 2]\n"}}interact


telnet自动登录(适合先发送用户名,再发送密码的情况):

#!/usr/bin/expectset timeout 20set name [lindex $argv 1]set user [lindex $argv 0]set password [lindex $argv 2]spawn telnet $nameexpect "login:"send "$user\r"expect "Password:"send "$password\r"interact

用法都是一样,就是  [脚本名  用户名 服务名 密码],例如[~/shell/login_telnet.exp hbocskf 10.45.44.169 hbocskf]

在item的profiles中,设置在General -> Command即可

后续只需要command+o呼出profiles界面,双击就能自动登录了,比自带的终端不知道高到哪里去了


0 0
原创粉丝点击