forked from chrisbier/APC_PDU_onoff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDC_outlet_onoff.sh
executable file
·165 lines (157 loc) · 4.87 KB
/
PDC_outlet_onoff.sh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/expect -f
# 1- Battery Backup ON
# 2- 16 port switch ON
# 3- Outlet 3 ON
# 4- Outlet 4 ON
# 5- Outlet 5 ON
# 6- Wifi Router ON
# 7- Subwoofer OFF
# 8- TV Streamer ON
# 9- Wii ON
# 10- Outlet 10 ON
# 11- Outlet 11 ON
# 12- Outlet 12 ON
# 13- Outlet 13 ON
# 14- Outlet 14 ON
# 15- Outlet 15 ON
# 16- Chromecast ON
# 17- Antenna ON
# 18- Outlet 18 ON
# 19- Outlet 19 ON
# 20- Outlet 20 ON
# 21- Outlet 21 ON
# 22- Outlet 22 ON
# 23- Outlet 23 ON
# 24- Sensi ON
# 25- Master Control/Configuration
# This Expect script was generated by autoexpect on Tue Oct 4 18:11:38 2016
# Expect and autoexpect were both written by Don Libes, NIST.
#
# Note that autoexpect does not guarantee a working script. It
# necessarily has to guess about certain things. Two reasons a script
# might fail are:
#
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts. If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character. This
# pacifies every program I know of. The -c flag makes the script do
# this in the first place. The -C flag allows you to define a
# character to toggle this mode off and on.
set outletnum [lindex $argv 0]; # Grab the first command line parameter
set onoffnum [lindex $argv 1]; # Grab the second command line parameter
set force_conservative 1 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
#
# 2) differing output - Some programs produce different output each time
# they run. The "date" command is an obvious example. Another is
# ftp, if it produces throughput statistics at the end of a file
# transfer. If this causes a problem, delete these patterns or replace
# them with wildcards. An alternative is to use the -p flag (for
# "prompt") which makes Expect only look for the last line of output
# (i.e., the prompt). The -P flag allows you to define a character to
# toggle this mode off and on.
#
# Read the man page for more info.
#
# -Don
set timeout -1
spawn $env(SHELL)
match_max 100000
expect -exact "cymor@myserver:~/bin\$ "
send -- "ssh apc@192.168.100.36\r"
expect -exact "ssh apc@192.168.100.36\r
Authenticated with partial success.\r\r
apc@192.168.100.36's password: "
send -- "apc\r"
send -- "1\r"
send -- "2\r"
send -- "1\r"
send -- "\r"
send -- "$outletnum\r"
send -- "1\r"
#expect -exact "
#
#\r------- Control Outlet --------------------------------------------------------\r
#\r
# Name : Sensi\r
# Outlet : 24\r
# State : ON\r
# Bank : 2\r
#\r
# 1- Immediate On\r
# 2- Immediate Off\r
# 3- Immediate Reboot\r
# 4- Delayed On\r
# 5- Delayed Off\r
# 6- Delayed Reboot\r
# 7- Cancel \r
#\r
# ?- Help, <ESC>- Back, <ENTER>- Refresh, <CTRL-L>- Event Log\r
#> "
send -- "$onoffnum\r"
#expect -exact "2\r
# -----------------------------------------------------------------------\r
# Immediate Off\r
#\r
# This command will immediately turn\r
# outlet 24 named 'Sensi' OFF.\r
#\r
# Enter 'YES' to continue or <ENTER> to cancel : "
send -- "YES\r"
#expect -exact "YES\r
# Command successfully issued.\r
#\r
# Press <ENTER> to continue..."
send -- "\r"
#expect -exact "\r
#
#
#\r------- Control Outlet --------------------------------------------------------\r
#\r
# Name : Sensi\r
# Outlet : 24\r
# State : OFF\r
# Bank : 2\r
#\r
# 1- Immediate On\r
# 2- Immediate Off\r
# 3- Immediate Reboot\r
# 4- Delayed On\r
# 5- Delayed Off\r
# 6- Delayed Reboot\r
# 7- Cancel \r
#\r
# ?- Help, <ESC>- Back, <ENTER>- Refresh, <CTRL-L>- Event Log\r
#> "
send -- ""
#expect -exact "
#
#\r------- Sensi -----------------------------------------------------------------\r
#\r
# Name : Sensi\r
# Outlet : 24\r
# State : OFF\r
# Bank : 2\r
#\r
# 1- Control Outlet \r
# 2- Configure Outlet \r
#\r
# ?- Help, <ESC>- Back, <ENTER>- Refresh, <CTRL-L>- Event Log\r
#> "
send -- ""
send -- "\r"
send -- ""
send -- ""
send -- ""
send -- "4\r"
expect eof