On Thu, Sep 19, 2024 at 10:44:11AM +0000, Mohan.Prasad@microchip.com wrote:
Hello Andrew,
Thank you for the suggestion.
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Since you have batteries included python:
ethtool --json enp2s0 [sudo] password for andrew: [ { "ifname": "enp2s0", "supported-ports": [ "TP","MII" ], "supported-link-modes": [ "10baseT/Half","10baseT/Full","100baseT/Half","100baseT/Full","1000b aseT/ Full" ], "supported-pause-frame-use": "Symmetric Receive-only", "supports-auto-negotiation": true, "supported-fec-modes": [ ], "advertised-link-modes": [ "10baseT/Half","10baseT/Full","100baseT/Half","100baseT/Full","1000b aseT/ Full" ], "advertised-pause-frame-use": "Symmetric Receive-only", "advertised-auto-negotiation": true, "advertised-fec-modes": [ ], "auto-negotiation": false, "master-slave-cfg": "preferred slave", "master-slave-status": "unknown", "port": "Twisted Pair", "phyad": 0, "transceiver": "external", "supports-wake-on": "pumbg", "wake-on": "d", "link-detected": false } ]
You can use a json library to do all the parsing for you.
I tried running the --json option with the ethtool ("ethtool --json enp9s0"),
however I am not getting the above output.
Instead it always throws "ethtool: bad command line argument(s)" I am figuring out what might be missing (or any suggestions would be
helpful).
Are you using real ethtool, or busybox? What version of ethtool? I'm using 6.10, but it looks like JSON support was added somewhere around 5.10.
I have been using ethtool 6.7, updating to ethtool 6.10 solved the problem.
It would be good to gracefully handle this. Have the test fail with a human readable error indicating ethtool is too old, rather than just throwing an exception etc.
Digging through the git history, it seems like 6.10 was actually the first version that supported this:
commit bd1341cd2146bfb89e1239546299102339acbf4d Author: Fabian Pfitzner f.pfitzner@pengutronix.de Date: Fri Jul 19 10:55:44 2024 +0200
add json support for base command
Most subcommands already implement json support for their output. The base command (without supplying any subcommand) still lacks this option. This patch implments the needed changes to get json output, which is printed via "ethtool --json [iface]"
The following design decision were made during implementation: - json values like Yes/No are printed as true/false - values that are "Unknown" are not printed at all - all other json values are not changed - keys are printed in lowercase with dashes in between
Signed-off-by: Fabian Pfitzner f.pfitzner@pengutronix.de
Andrew