Chinaunix首页 | 论坛 | 博客
  • 博客访问: 398606
  • 博文数量: 77
  • 博客积分: 2031
  • 博客等级: 大尉
  • 技术积分: 855
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 19:54
文章分类

全部博文(77)

文章存档

2011年(1)

2009年(52)

2008年(24)

我的朋友

分类: LINUX

2008-10-16 17:39:50

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

 

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"

阅读(4774) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~