-
Notifications
You must be signed in to change notification settings - Fork 1
/
power_cycle
executable file
·63 lines (53 loc) · 1.12 KB
/
power_cycle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env -S expect -f
proc shift {list} {
set result ""
upvar 1 $list ll
set ll [lassign $ll result]
return $result
}
proc usage_exit {} {
send_user [subst -nocommand {Usage: $::argv0 <interface number> [on|off]\n}]
exit 1
}
if {[llength $argv] == 0 || [llength $argv] > 2} {
usage_exit
}
set interface [format "ge-0/0/%d" [shift argv]]
set on 1
set off 1
if {[llength $argv] == 1} {
switch -- [shift argv] {
on { set off 0 }
off { set on 0 }
default { usage_exit }
}
}
log_user 0
spawn ssh lead-mgmt
expect "root@lead:RE:0% "
send "cli\r"
expect "root@lead> "
send "set cli screen-length 0\r"
expect "root@lead> "
send "configure\r"
expect "root@lead# "
if { $off } {
send_user "Turning off $interface..."
send "set poe interface $interface disable\r"
expect "root@lead# "
send "commit\r"
expect "root@lead# "
send_user " ✓\n"
}
if { $on } {
if { $off } { sleep 1 }
send_user "Turning on $interface..."
send "delete poe interface $interface\r"
expect "root@lead# "
send "commit\r"
expect "root@lead# "
send_user " ✓\n"
}
send "exit\r"
expect "root@lead> "
send "\x01\x18"