分类: 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"