Skip to content

Instantly share code, notes, and snippets.

@fidergo-stephane-gourichon
Forked from awaxa/outlet
Created June 17, 2018 21:19
Show Gist options
  • Save fidergo-stephane-gourichon/1f3f9be884115d8573693f03e7bd8fd9 to your computer and use it in GitHub Desktop.
Save fidergo-stephane-gourichon/1f3f9be884115d8573693f03e7bd8fd9 to your computer and use it in GitHub Desktop.
apc pdu outlet expect script
#!/usr/bin/expect
set timeout 3
if {[llength $argv] == 0} {
send_user "Usage: outlet [1-8] [on|off|reboot] \n"
exit 1
}
set number [lindex $argv 0]
set onoff [lindex $argv 1]
set offstring "off"
set state "1"
if { [string compare $onoff $offstring] == 0 } {
set state "2"
}
set rebootstring "reboot"
if { [string compare $onoff $rebootstring] == 0 } {
set state "3"
}
spawn telnet pdu
expect "User Name :" { send "apc\r" }
expect "Password :" { send "apc\r" }
# device manager
expect "> " { send "1\r" }
# outlet management
expect "> " { send "2\r" }
# outlet control
expect "> " { send "1\r" }
# outlet number
expect "> " { send "$number\r" }
# control outlet
expect "> " { send "1\r" }
# state
expect "> " { send "$state\r" }
# control outlet
expect "cancel : " { send "YES\r" }
expect "..." { send "\r" }
expect "> " { send \033 }
expect "> " { send \033 }
expect "> " { send \033 }
expect "> " { send \033 }
expect "> " { send \033 }
expect "> " { send "4\r" }
@fidergo-stephane-gourichon
Copy link
Author

Compared to upstream, adds "reboot" option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment