Power cycle POE ports via SSH on TP-Link T1500G-10PS

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Power cycle POE ports via SSH on TP-Link T1500G-10PS

Post by ben53252642 »

Hey folks,

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
These are the definitions I'm using in /etc/monit/monitrc to automatically cycle the port if a Raspberry does not respond to ping for a couple of cycles.

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"
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
kurb77
Posts: 2
Joined: Tuesday 28 January 2014 17:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Melun(France)
Contact:

Re: Power cycle POE ports via SSH on TP-Link T1500G-10PS

Post by kurb77 »

thank for your script, it's work very well.
i removed the sleep commands without any impact
thank
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests