From 5bbee7bfdd0c483d0f8cc225b5cb53803aa6a937 Mon Sep 17 00:00:00 2001 From: zachir Date: Thu, 9 Feb 2023 14:13:09 -0600 Subject: add ups_ctl_15 --- ups_ctl_15.py3 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 ups_ctl_15.py3 diff --git a/ups_ctl_15.py3 b/ups_ctl_15.py3 new file mode 100755 index 0000000..17dd59c --- /dev/null +++ b/ups_ctl_15.py3 @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import sys + +if not (len(sys.argv) == 5): + print("Number of arguments doesn't make sense!\n") + exit(1) + +from telnetlib import Telnet as tn + +timeout = 8 + +ups = tn(sys.argv[1],5214,timeout) +ups.read_until(b"login: ",timeout) +ups.write(b"localadmin\r\n") +ups.read_until(b"Password: ",timeout) +ups.write((sys.argv[2] + "\r\n").encode("ascii")) +ups.read_until(b">> ",timeout) +ups.write(b"e\r\n") +ups.read_until(b"$> ",timeout) +if (sys.argv[3] == "on") or (sys.argv[3] == "off"): + ups.write(("loadctl " + sys.argv[3] + " -o 1\r\n").encode("ascii")) + ups.read_until(b'[y/n]? ',timeout) + ups.write(b"y\r\n") + ups.read_until(b'$> ',timeout) +if (sys.argv[4] == "on") or (sys.argv[4] == "off"): + ups.write(("loadctl " + sys.argv[4] + " -o 2\r\n").encode("ascii")) + ups.read_until(b'[y/n]? ',timeout) + ups.write(b"y\r\n") + ups.read_until(b'$> ',timeout) +ups.write(b"exit\r\n") +ups.read_until(b"Farewell, localadmin.\r\r\n") -- cgit v1.2.3