#! /usr/bin/expect -f # QUAGGA_SHRU - runs 'show running-config' in Quagga services using Expect # Copyright (C) 2007 Matous Jan Fialka # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Note: this script is NOT good example of writting code in Expect at all. if { [llength $argv] != 4 } { puts "Expect 'show running-config' script for Quagga services." puts "Copyright (C) 2007 Matous Jan Fialka." puts "Released under the terms of GNU/GPL.\n" puts "Usage: hostname { service | port } disable_password enable_password\n" puts "Example: qshru.exp localhost zebra secret password\n" puts "Use with extreme caution! You have been warned..." exit 1 } set hostname [lindex $argv 0] set service [lindex $argv 1] set disable_password [lindex $argv 2] set enable_password [lindex $argv 3] set disable_prompt "^*>" set enable_prompt "^*#" set disable_password_prompt "Password:" set enable_password_prompt "Password:" set terminal_length_command "terminal length 0" set enable_command "enable" set disable_command "disable" set quit_command "quit" set show_running_config_command "show running-config" set timeout 10 set telnet /usr/bin/telnet spawn "$telnet" "$hostname" "$service" expect "$disable_password_prompt" send "$disable_password\r" expect "$disable_prompt" send "$terminal_length_command\r" expect "$disable_prompt" send "$enable_command\r" expect "$enable_password_prompt" send "$enable_password\r" expect "$enable_prompt" send "$show_running_config_command\r" expect "$enable_prompt" send "$disable_command\r" expect "$disable_prompt" send "$quit_command\r" expect eof puts "\nBye, bye..." exit 0