#!/usr/bin/ruby
require 'pty' require 'expect'
ip = ARGV[0] outlet_id = ARGV[1]
PTY.spawn( 'telnet ' + ip ) do |read,write,pid| write.sync = true $expect_verbose = true
read.expect(/User Name : $/,3) write.print "#######\r"
read.expect(/Password : $/) write.print "#######\r"
read.expect(/^>.*/,2) write.print "1\r" #Type 1 for "Device Manager"
read.expect(/^>.*/,2) write.print "2\r" #Type 2 for "Outlet Management"
read.expect(/^>.*/,2) write.print "1\r\r" #Type 2 for "Outlet Control/Configuration"
read.expect(/^>.*/,2) write.print "#{outlet_id}\r\r" #Enter the required outlet number"
read.expect(/^>.*/,2) write.print "1\r" #Select 1 to control the outlet"
read.expect(/^>.*/) write.print "3\r" #Select 3 for immediate reboot"
read.expect(/cancel.*:/) #Select 1 to control the outlet" write.print "YES\r" # outlet has now been power cycled
read.expect(/Press to continue./) #press enter to return to menu write.print "\r" read.expect(/^>./)
end # end pty spawn