| 网站首页 | 硬件维修 | 应用学院 | 网络组建 | 网站制作 | 菜鸟黑客 | 编程之道 | 数码大全 | 娱乐休闲 | 软件下载 | 在线视频 | 请您留言 | 技术论坛 | 
专 题 栏 目
最 新 热 门
最 新 推 荐
相 关 文 章
  • 代理服务器软件冲突导致的网…

  • MSN Sniffer 嗅探MSN Messen…

  • 网易推出280M网络硬盘—网盘

  • Google Earth三维地图服务使…

  • 快乐用网 手把手教你带网络名…

  • Google的特殊服务:无线搜索

  • Google的特殊服务:邮购搜索

  • 让图片在网络永存 广州视窗相…

  • 快快申请 streamload提供10G…

  • 代理服务器软件冲突导致的网…

  • Q
    您现在的位置: 我是IT人 >> 应用学院 >> 操作系统 >> Unix >> 教程正文
    从服务器能够到达的所有网络设备里面提取设备配置信息           
    从服务器能够到达的所有网络设备里面提取设备配置信息
    作者:网络 文章来源:转载 点击数: 更新时间:2005-8-15
    [ 字体:缩小 正常 放大 | 双击自动滚屏 ]
    请选择合适的字体颜色:


    本工具用于从网络设备(CISCO)中提取配置文件,并保存到一个文本文件中。
    需要 expect 软件支持, 如果你的操作系统没有这个软件,请根据需要下载
    在 sco unix 中,请到 http://www.sco.com/skunkware/中下载, 三个软件: expect , tcl, tk 并安装。

    主程序-----dome.sh
    #!/bin/sh

    counter=0

    Usage()
    {
    echo "
    Usage: $0 [iplist_filename]
    功能:本程序用于读网络设备的配置信息。
    参数: iplist_filename, 指定需要工作的网络设备文件。
    文件格式:
    节点编号 ip地址 Telnet密码 超级用户密码 节点设备说明

    如果没有定义iplist_filename, 缺省文件名为:iplist
    程序输入文件: iplist.out 或者 自定义文件名.out \n\n"

    exit 1

    }

    [ $# -eq 0 ] && input="iplist"
    [ $# -eq 1 ] && input=$1
    [ $# -gt 1 ] && Usage


    output="$input.out"
    [ -r $input ] || {
    echo "Error: Can't open file:$input"
    exit 1
    }
    echo "">$output

    lines=`wc -l $input|awk '{ print $1 }'`

    while read node host pass1 pass2 name
    do
    counter=`expr $counter + 1 `
    echo "\nGet configure from [ $host ], Please wait...\t[$counter/$lines]\c">&2
    echo "============== begin ==============================\n">>$output
    echo "NODE=$node">>$output
    echo "NAME=$name">>$output
    ./router.cmd $host $pass1 $pass2>>$output
    case $? in
    0) echo "\t----\c">&2; continue;;
    1) echo "\tE--- error \c">&2; continue;;
    2) echo "\t-E-- error \c">&2; continue;;
    3) echo "\t--E- error \c">&2; continue;;
    4) echo "\t---E error \c">&2; continue;;
    *) echo "\t**** error \c">&2; continue;;
    esac
    echo "-------------- end --------------------------------\n">>$output
    done<$input

    echo "\n===================\nCreate output file: $output">&2

    :em02: [b:7ce538da72]调用程序 router.cmd [/b:7ce538da72]
    #!/usr/local/bin/expect --
    # 登陆路由器的一个命令 Script for expact
    # 重要变量说明:
    # routerip=路由器telnet登陆ip地址
    # passwd1=路由器telnet登陆密码
    # passwd2=路由器超级用户密码
    # ---------------------------------------------------
    if $argc!=3 {
    send_user "Usage: router.cmd routerip passwd1 passwd2\n"
    exit 9
    }
    set ROUTERIP [lindex $argv 0]
    set PASSWORD1 [lindex $argv 1]
    set PASSWORD2 [lindex $argv 2]
    set TIMEOUT 30
    set debug_flag 1
    send_user "##### BEGIN\n"
    spawn /usr/bin/telnet $ROUTERIP 23

    set timeout $TIMEOUT
    expect {
    timeout {
    send_user "Error 1: router ip can't arrived.\n"
    send_user "##### END\n\n"
    exit 1
    }
    "refused" {
    send_user "Error 1: connection Failed.\n"
    send_user "##### END\n\n"
    exit 1
    }
    "*assword: " { send "$PASSWORD1\r" }
    }

    set timeout $TIMEOUT
    expect {
    timeout {
    send_user "\nError 2: invalid telnet password...\n"
    send_user "##### END\n\n"
    exit 2
    }
    "*>" { send "enable\r" }
    }


    set timeout $TIMEOUT
    expect {
    timeout {
    send_user "\nError 3: time out.\n"
    send_user "##### END\n\n"
    exit 3
    }
    "Password: " { send "$PASSWORD2\r" }
    }


    set timeout $TIMEOUT
    expect {
    timeout {
    send_user "\nError 4: Invalid password for super user...\n"
    send_user "##### END\n\n"
    exit 3
    }
    "*#" { send "term len 0 \r" }
    }

    expect "*#"
    send "show run\r"
    expect "*#"
    send "exit\r"
    send_user "\n##### END\n\n"
    exit 0

    =============以上程序已经在 Sco Unix OSR5 里面测试通过

    [1]

    教程录入:小秦    责任编辑:小秦 
  • 上一篇教程:

  • 下一篇教程:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    | 设为首页 | 加入收藏 | 联系站长 | 关于我们 | 友情链接 | 版权申明 |