02.02.2021, 13:02
Hi
I'd like to automate the power cycle of a POE port on a Unifi Switch. The Unifi docs say this can be achieved by connecting to the device via a SSH key and then issuing some telnet commands. I can run these commands ok from the terminal window of my desktop, however am not to sure how to initial a ssh connection from logic machine / CBUS SHAC.
Here the sequence of commands that run ok from my desktop Mac to power cycle port 15.
Here's the beginnings of my LM script to issue the telnet commands. Can anyone advise how to modify the script to SSH to the switch with an SSH key (the key is in the id_rsa file in the above example)
Any advice would be greatly appreciated
Kind Regards
James
I'd like to automate the power cycle of a POE port on a Unifi Switch. The Unifi docs say this can be achieved by connecting to the device via a SSH key and then issuing some telnet commands. I can run these commands ok from the terminal window of my desktop, however am not to sure how to initial a ssh connection from logic machine / CBUS SHAC.
Here the sequence of commands that run ok from my desktop Mac to power cycle port 15.
Code:
ssh -i /Users/james/.ssh/id_rsa admin@192.168.1.100#
telnet localhost 23
enable
configure
interface 0/15
poe opmode shutdown
poe opmode auto
exit
exit
exit
telnet localhost 23
exit
Here's the beginnings of my LM script to issue the telnet commands. Can anyone advise how to modify the script to SSH to the switch with an SSH key (the key is in the id_rsa file in the above example)
Code:
function resetPOESwitchPort(switchport)
local socket = require("socket").tcp()
local response, err = socket:connect('192.168.1.100', 23)
if response then
-- SSH connection established so issue telnet commands
socket:send('telnet localhost 23\r\n')
response = socket:receive(5)
log(response)
socket:send('telnet localhost 23\r\n')
response = socket:receive(5)
log(response)
socket:send('enable\r\n')
response = socket:receive(5)
log(response)
socket:send('configure\r\n')
response = socket:receive(5)
log(response)
socket:send('interface 0/' .. switchport .. '\r\n')
response = socket:receive(5)
log(response)
socket:send('poe opmode shutdown\r\n')
response = socket:receive(5)
log(response)
socket:send('poe opmode auto\r\n')
response = socket:receive(5)
log(response)
socket:send('exit\r\n')
response = socket:receive(5)
log(response)
socket:send('exit\r\n')
response = socket:receive(5)
log(response)
socket:send('exit\r\n')
response = socket:receive(5)
log(response)
socket:send('telnet localhost 23\r\n')
response = socket:receive(5)
log(response)
socket:send('exit\r\n')
response = socket:receive()
log(response)
socket:close()
else
-- No connnection response
log ('Unable to connect to switch')
tcp:close()
end
end
Any advice would be greatly appreciated
Kind Regards
James