diff options
author | zachir <zachir@librem.one> | 2023-02-09 14:13:09 -0600 |
---|---|---|
committer | zachir <zachir@librem.one> | 2023-02-09 14:13:09 -0600 |
commit | 5bbee7bfdd0c483d0f8cc225b5cb53803aa6a937 (patch) | |
tree | b71f75aa1dbecbad9b012034ed2e6b4db330c11b | |
parent | 3c1e920ccd38dc5360809dc171ef525bcc9b9136 (diff) |
add ups_ctl_15
-rwxr-xr-x | ups_ctl_15.py3 | 32 |
1 files changed, 32 insertions, 0 deletions
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") |