Skip to content

Working upscmd.py file with DSM 7.2 and latest telnetlib #9

@nntantidakis

Description

@nntantidakis

Latest libs require encoding of strings. Here is a fully working upscmd.py file, that i personally tested that its working.

#!/bin/python2
import sys
import telnetlib

user = "<username>"
pwd = "<password>"

if len(sys.argv) == 2:
    cmd = sys.argv[1]
else:
    print("the ups command to issue is missing.")
    print("example: upscmd.py beeper.enable")
    exit(1)


tn = telnetlib.Telnet("127.0.0.1", 3493)

tn.write(str.encode("USERNAME {0}\n".format(user)))
response = tn.read_until(b"OK", timeout=2)
print ("USERNAME cmd status: {0}".format(response.strip()))

tn.write(str.encode("PASSWORD {0}\n".format(pwd)))
response = tn.read_until(b"OK", timeout=2)
print ("PASSWORD cmd status: {0}".format(response.strip()))

tn.write(str.encode("INSTCMD ups {0}\n".format(cmd)))
response = tn.read_until(b"OK", timeout=2)
print ("INSTCMD cmd status: {0}".format(response.strip()))

tn.write(str.encode("LOGOUT\n"))
print (tn.read_all())

Also the command for service restart is synosystemctl restart ups-usb. And while running the script if you get access-denied, set to upsd.users the actions to SET and instcmd to ALL. After that restart service, and it will work like a charm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions