文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>tcl学习笔记(2)-expect实现telnet和ssh

tcl学习笔记(2)-expect实现telnet和ssh

时间:2009-04-03  来源:liyf0371

这个两个功能在以后的工作中可以以函数实现,完成特定功能。

 

1.SSH到linux主机上查看linux内核版本号

 

#!/usr/expect/bin/expect

 

set HOSTIP [lindex $argv 0]

set LOGIN [lindex $argv 1]

set PASS [lindex $argv 2]

 

set timeout 1

set cmd {uname -a}

 

if {$argc<3} {

        puts stderr "Usage:$argv0 hostip login password.\n"

        exit 1

}

 

send_user "argv0:  $argv0\n"

send_user "argv:  $argv\n "

 

spawn ssh $LOGIN@$HOSTIP

expect_after eof { exit 0 }

 

expect "yes/no" { send "yes\r" }

expect "password:" { send "$PASS\r" }

expect "#"

send "$cmd\r"

expect "*\r"

send "exit\r"

 

 

 

2.telnet到3750上添加一条静态路由

 

#!/usr/expect/bin/expect

 

spawn telnet 10.255.255.240

expect "Username:"

send "admin\n"

expect "Password:"

send "XXXXXX\n"

expect "3750>"

send "en\n"

expect "Password:"

send "XXXXXX\n"

expect "3750#"

send "ping 192.168.100.100\n"

expect "3750#"

send "config t\n"

expect "#"

send "ip route 123.2.1.1 255.255.255.255 null0\n"

expect "#"

 

send_user "\n\nOver\n\n"

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载