routeviews collector script

http://www.routeviews.org/scripts/collector

#!/usr/bin/expect -f

#
#send_error "$argv0 [lrange $argv 0 3]\r\n"
#
#	The script uses Expect, which is a package based on Tcl.  
#	You call it with the following syntax:
# 
# collector route-views.oregon-ix.net NONE NONE 'route-views.oregon-ix.net>' | grep -v "^ --More-- "
#
#	The trailing grep is required to filter out the garbage 
#	inserted by the console every 512 lines.  This is the bit 
#	that fixed the console timeout problem, BTW.  Here's the script:
#
#	Originally written by Sean McCreary (mccreary@pch.net)
#
# 
# ===========================
# 
# Copyright (c) 2001 Sean McCreary   All rights reserved.
# 
# This software was produced with support from Packet Clearing House (PCH),
# a nonprofit research institute supporting investigation and operations in
# the area of Internet traffic exchange and global IP routing economics.
# Please visit our web site at  for more information
# about PCH.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission
# 
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# 
# ===========================

set timeout 30
set hostname [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set prompt   [lindex $argv 3]
#send_error "Hostname is $hostname\r\n"
#send_error "Username is $username\r\n"
#send_error "Password is $password\r\n"
#send_error "Prompt is $prompt\r\n"
spawn telnet $hostname
if {[string compare $username "NONE"] != 0} {
    expect "sername:"
    send "$username\r"
}
if {[string compare $password "NONE"] != 0} {
    expect "assword:"
    send "$password\r"
}
expect "$prompt"
send "term len 0\r"
expect "$prompt"
send "sh ip bgp sum\r"
expect "$prompt"
send "sh ip bgp dam\r"
expect "$prompt"
send "term len 512\r"
expect "$prompt"
set not_done 1
send "sh ip bgp\r"
while { $not_done } {
    expect timeout {
        send_error "Sending null...\r"
        send -null
    } "$prompt" {
        set not_done 0
    } eof {
        send_error "Connection closed prematurely, dump may be truncated\r\n"
        exit 1
    } " --More-- " {
        send " ";
    }
}
send "quit\r"
exit
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s