linux下的ssh、telnet登录脚本(tcl)

来源:互联网 发布:仿真分析数据 编辑:程序博客网 时间:2024/06/06 17:21

 操作系统:linux(feroda4)
tcl版本:tclsh8.4
expect:5.43.0

ssh登录脚本
#!/usr/bin/tclsh8.4

package require Expect

set user "root"
set host "10.2.26.30"
spawn ssh $user@$host
expect {
             -re "password: $"       {exp_send "密码/r"; exp_continue}
}


telnet登录脚本
#!/usr/bin/tclsh8.4

package require Expect

set user "test"
set host "10.2.26.30"
set port "23"
spawn telnet $host $port
expect {
            -re "login: $"         {exp_send "$user/r"; exp_continue}
            -re "Password: $"     {exp_send "test密码/r"}
}


PS:10.2.26.30为linux主机,若登录其他设备,更改匹配字符即可

 

http://hi.baidu.com/gfshop/blog/item/2b73a000a5528985e950cd8b.html

原创粉丝点击