This is a script I wrote for power cycling POE ports on my TP-Link T1500G-10PS POE Switch via SSH.
I use Monit to monitor Raspberry Pi hosts connected to the POE switch and then get Monit to power cycle the POE switch port number if all else fails.
Requires: apt-get install expect sshpass
Usage example to powercycle POE port 8: ./poecycle.sh 8
Note that you can't see output in the bash terminal while the commands are running so be patient and wait for it to finish (which should be around 23 seconds).
poecycle.sh
Code: Select all
#!/usr/bin/expect -f
# Requires: apt-get install expect sshpass
# Example usage to power cycle POE port 8: ./poecycle.sh 8
set timeout 60
set poeport [lindex $argv 0]
spawn sshpass -p PASSWORD ssh -o KexAlgorithms=+diffie-hellman-group1-sha1 -o Ciphers=+aes128-cbc -o HostKeyAlgorithms=+ssh-dss -o StrictHostKeyChecking=no [email protected]
expect "T1500G-10PS>"
sleep 1
send -- "enable\r"
sleep 1
send -- "config\r"
sleep 1
send -- "interface gigabitEthernet 1/0/$poeport\r"
sleep 1
send -- "power inline supply disable\r"
sleep 10
send -- "power inline supply enable\r"
send -- "exit\r"
send -- "exit\r"
send -- "exit\r"
send -- "exit\r"
expect eof
Code: Select all
# NTP Server Raspberry on POE 8
check host ntpserver_raspberry_poe8 with address 192.168.0.53
if failed ping for 2 cycles then exec "/etc/monit/benscripts/poecycle.sh 8"
# NTP Server Raspberry on POE 7
check host zigbee2mqtt_raspberry_poe7 with address 192.168.0.72
if failed ping for 2 cycles then exec "/etc/monit/benscripts/poecycle.sh 7"
# Homeseer Raspberry on POE 6
check host homeseer_raspberry_poe6 with address 192.168.0.84
if failed ping for 2 cycles then exec "/etc/monit/benscripts/poecycle.sh 6"