summaryrefslogtreecommitdiff
path: root/ups_ctl_15.py3
blob: 17dd59ce841306e41a1a0c38fcd234a9608653b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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")