[nsp] Script for gathering logs from routers?
james
hackerwacker at cybermesa.com
Thu Oct 30 17:01:36 EST 2003
[root at tarpit bin]# vi 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-- "
# New syntax: collector <host> <usr> <pwd> <prompt when finished cmd, in ' '> <cmd to run, in ' '> <port, NO ' '>
# 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 at pch.net)
#
#
# ===========================
#
# Copyright (c) 2001 Sean McCreary <mccreary at pch.net> 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 <http://www.pch.net> 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]
set cmd [lindex $argv 4]
#set cmd2 [lindex $argv 5]
set port [lindex $argv 6]
#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 $port
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 "$cmd\r"
#\expect "$prompt"
#send "$cmd2\r"
#expect "$prompt"
set not_done 1
send "$cmd\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
More information about the cisco-nsp
mailing list