# Simple script for controlling a Synaccess NP-08 remote power strip via telnet. 
# The NP-08 can be used to power cycle a router prior to a test run with CDRouter.
#
# This script takes two arguments - the IP address of the NP-08 and the outlet
# number. The NP-08 has 8 remotely controllable outlets.
#
# 2007 QA Cafe www.qacafe.com
# support@qacafe.com
#
# Revision 1, July 17, 2007 

set address [ lindex $argv 0 ]
set outlet [ lindex $argv 1 ]

if { $outlet <= 0 || $outlet > 8 } {
	puts "powerCycle.tcl failure: selected power outlet index was $outlet; must be between 1 and 8."
	exit
} 

spawn -console telnet $address
expect {
	"Make sure to set Telnet mode to Local Echo Off" {
		send "rb $outlet\r"
		expect "Outlet-$outlet rebooted."
		send "logout\r"
		send "\r"
		puts "powerCycle.tcl success: outlet $outlet on host $address successfully power cycled."
		exit
	}
	"Unable to connect to remote host" {
		puts "powerCycle.tcl failure: unable to connect to the remote host."				
		exit
	}
	timeout	{
		puts "powerCycle.tcl failure: connection timed out."	
		exit 
	}
}

		






