linuxbashusbups

Script to read USB UPS status


I have a UPS attached via USB port to my Linux machine. Unfortunately the UPS is unsupported and doesn't show up as a recognized device. However it DOES show up correctly with the lsusb command.

I'd like to read the battery status from my UPS via a simple bash script (triggered by cron for example). I don't want a fully functional script as it would require to know the protocol of the specific UPS; I just want to create a script to write raw commands and read raw responses to/from the UPS given the known USB address, then it will be up to me to encode the actual command and parse the response.


Solution

  • You might be able to use the normal echo command to send strings directly to a device, like:

    echo "some command" > /dev/usbXXX
    

    To get the output you might be able to just read from it using e.g. cat:

    cat /dev/usbXXX | grep "what you're looking for"