Can I pipe lshw warnings to /dev/null when I run it as a standard user?

629 Views Asked by At

I'm trying to create an alias for getting memory on my machine, currently I have alias mem="lshw | grep size | awk -F: '{print $2}'", and when I run it as a non-super user, I get the following warning message:

WARNING: you should run this program as super-user.
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.
      size: 23GiB

I'm not worried about the results being potentially incomplete, in fact when I diff the output when running as root vs a standard user, it's exactly the same. Does anybody know how to get rid of these warnings? I tried piping stderr to /dev/null, but that didn't work. Does anyone else know how to get rid of these warnings?

4

There are 4 best solutions below

0
jeremysprofile On BEST ANSWER

Can I interest you in

alias mem='free -g | grep Mem | awk '\''{print $2 " GiB"}'\'

free -m will give MiB; you can change the " GiB" part to whatever you want (or remove it).

I don't have lshw installed on my machine, so I can't help you debug your version, unfortunately.

1
Logu On
alias mem="lshw 2> /dev/null| grep size | awk -F: '{print $2}'"

Alternatively you can use free or read from /proc/meminfo

cat /proc/meminfo |grep MemTotal
2
Artur Kudrin On

Or add a one grep:

... | grep "size:"

0
Eric Wikman On

I'm not sure how you piped to dev/null, but this works for me:

lshw 2> /dev/null | grep size | awk -F: '{print $2}'

Ignoring that there are other tools more suited to getting the memory, if there is something you need and lshw is your only option, you would be better suited to use -json or -xml output and use a tool to parse it like jq or xmllint. The version of lshw on my distro outputs invalid json that can't be parsed, but does have valid xml output.

This would accomplish your goal, although the path may very well be different for you:

lshw -xml 2> /dev/null | xmllint --xpath '/list/node/node/node[@id="memory"]/size/text()' -