#!/usr/local/bin/expect -- ####################################################################################### # # # NAME: tccreset.exp # # AUTHOR: chux0r.org (C) 2001, Licensed under the LGPL: # http://www.gnu.org/copyleft/lesser.txt # PURPOSE: Resets modems on the TCC. # # This script takes 2+ args. The 1st being the IP of the TCC # # being connected to and 2+ being the modem port(s) needing reset. # # USAGE: tccreset 192.168.0.1 S3 S5 S9 S10 Sn... # # LANGUAGE: Expect - Thanks to Don Libes. ctg # # # ####################################################################################### # $argv0=tccreset.exp $0=chassis IP $1=modemnum (Sx) set ADMINLIST "admin@example.com";# <------ Set this before using!! set USERNAME "someusername\r";# <------ ...And this set PASS "somepass\r";# <------ ...And this. set USAGE "Usage: \$PATH/tccreset.exp \[ip|hostname\] \[modemport\] (\[modemport\]...)" set DATA_F "/tmp/tccreset.log" set argc [llength $argv] if ($argc<2) { puts "tccreset needs at least 2 arguments\n$USAGE";exit } spawn telnet [lindex $argv 0] expect { timeout {puts "connection to host timed out.";exit} "denied" {puts "connection denied.";exit} "refused" {puts "connection refused.";exit} "closed" {puts "connection terminated.";exit} "Unknown host" {puts "host not known.";exit} "host did not respond" {puts "host did not respond";exit} "login" } send $USERNAME expect "Password" send $PASS expect { "Invalid Login" {puts "incorrect password given.";exit} "login:" {puts "invalid login.";exit} "Command" } log_file -a -noappend $DATA_F for {set i 1} {$i<$argc} {incr i} { set MODEM [lindex $argv $i] send "reset $MODEM\r" expect { "Error:" {puts "Syntax error on reset. Modem $MODEM not reset."} "Resetting port" {puts "$MODEM reset by autoscript."} } } send "done\r" log_file exec mail -s "TCC AutoCorrection executed on [lindex $argv 0]" $ADMINLIST < $DATA_F exec rm $DATA_F exit