Anyone with a nvidia card that can tell me the results of this command?
gpudriver=`sudo lshw -c video |grep 'driver=' |awk '{ print $2}'`
( if the gpu manufacturer is amd the results are "driver=amdgpu" )
gpudriver=`sudo lshw -c video |grep 'driver=' |awk '{ print $2}'`
Code: Select all
$ sudo lshw -c video |grep 'driver=' | awk '{ print $2}'
driver=nvidia
Code: Select all
inxi -G | grep "Graphics:" | awk -F ".:" '{ print $4 }' | awk '{ print $1 }'
Code: Select all
#!/bin/bash
GRAPHICS_CARD_MANUFACTURER=$(inxi -G | grep "Device-1" | sed -e 's/.*Device-1: //g' -e 's/driver.* //g')
echo "DEVICE=$GRAPHICS_CARD_MANUFACTURER"
if grep -iq "nvidia" <<< "$GRAPHICS_CARD_MANUFACTURER"; then
echo "Nvidia device detected."
elif grep -iq "intel" <<< "$GRAPHICS_CARD_MANUFACTURER"; then
echo "Intel device detected."
elif grep -iq "amd" <<< "$GRAPHICS_CARD_MANUFACTURER"; then
echo "AMD device detected."
else
printf "Device not recognized from the list."
fi
Code: Select all
while IFS=':' read -a Line; do
if [ "${Line[0]// /}" == 'configuration' ]; then
for Field in ${Line[1]}; {
IFS='=' read -a KeyVal <<< "$Field"
if [ "${KeyVal[0]}" == 'driver' ]; then
gpudriver=${KeyVal[1]}
break
fi
}
break
fi
done <<< "$(lshw -c video 2> /dev/null)"
Code: Select all
while IFS='=' read -a Line; do
if [ "${Line[0]}" == 'DRIVER' ]; then
gpudriver=${Line[1]}
break
fi
done < /sys/class/graphics/fb0/device/uevent
Code: Select all
UEventFile='/sys/class/graphics/fb0/device/uevent'
if [ -f "$UEventFile" -a -r "$UEventFile" ]; then
while IFS='=' read -a Line; do
if [ "${Line[0]}" == 'DRIVER' ]; then
gpudriver=${Line[1]}
break
fi
done < /sys/class/graphics/fb0/device/uevent
elif type -P lshw &> /dev/null; then
# Fallback approach. Check for lshw(1) first.
while IFS=':' read -a Line; do
if [ "${Line[0]// /}" == 'configuration' ]; then
for Field in ${Line[1]}; {
IFS='=' read -a KeyVal <<< "$Field"
if [ "${KeyVal[0]}" == 'driver' ]; then
gpudriver=${KeyVal[1]}
break
fi
}
break
fi
done <<< "$(lshw -c video 2> /dev/null)"
else
: # Error out here, or otherwise handle it.
fi
this worked like a charm:
Code: Select all
inxi -G | grep "Graphics:" | awk -F ".:" '{ print $4 }' | awk '{ print $1 }'
if grep -iq "nvidia" <<< "$GRAPHICS_CARD_MANUFACTURER"; then
echo "Nvidia device detected."
Excellent! many thanks! yeah it's even better if the approach does not require special software installed. Although, I'm having some difficulty to understand everything in the script, but I'll take some time and thinking it over
I'm some familiar with < and << but never seen triple tags.Termy wrote: ⤴Thu Dec 10, 2020 10:42 am If you want speed and efficiency, refer to my post, as it's instant, and by default requires nothing be installed.
The use of '<<<' means that what follows will be provided via STDIN (standard input) of the given command, akin to piping. There's also '<<' for heredocs, and '<' for use with files. '<<<' typically gets used with command substitution ('$()' or '``') or process substitution ('<()'). BTW, '<<<' is for BASH and BASH-like shells; it won't work with Bourne Shell.
Code: Select all
grep -iq "nvidia" <<< "$GRAPHICS_CARD_MANUFACTURER"
Code: Select all
grep -iq "nvidia" $variable
Code: Select all
if grep something ; then
next commands
fi
Code: Select all
$ grep nvidia /sys/class/drm/card0/device/uevent
DRIVER=nvidia
Code: Select all
$ grep nvidia /sys/class/drm/card0/device/uevent ; echo $?
DRIVER=nvidia
0
Code: Select all
$ grep -qi nvidia /sys/class/drm/card0/device/uevent ; echo $?
0
Code: Select all
$ cat /sys/class/graphics/fb0/device/uevent
DRIVER=vesa-framebuffer
MODALIAS=platform:vesa-framebuffer
Code: Select all
$ cat /sys/class/drm/card0/device/uevent
DRIVER=nvidia
PCI_CLASS=30000
...
Code: Select all
$ lspci -k | grep -A2 VGA | grep "Kernel driver in use" | awk '{print $5}'
nvidia
Code: Select all
echo $variable | grep something
Yeah, `echo` is a built-in (enabled by default, but there is a GNU alternative '/bin/echo'), so that is fairly efficient. However, the use of a pipe in BASH does actually fork a sub-shell, but AFAIK `<<<` doesn't, or at least isn't mentioned in the BASH manual. What this means, is that the `<<<` (called a Here String, big brother to the Here Doc '<<') is a little bit more efficient, technically.
What do you mean? If you use 'nvidia' why is this example showing 'vesa-framebuffer' but the 2nd one shows 'nvidia'?1000 wrote: ⤴Thu Dec 10, 2020 11:55 amSomething else.I use Nvidia driver. If you want use "/sys/class/" I don't know if it's not betterCode: Select all
$ cat /sys/class/graphics/fb0/device/uevent DRIVER=vesa-framebuffer MODALIAS=platform:vesa-framebuffer
By reading the link above,What do you mean? If you use 'nvidia' why is this example showing 'vesa-framebuffer'
Probably I have second Intel graphic card inside CPU.Video card information in/sys/class/drm/It also contains the output interface supported by the graphics card, but only card+integer
So, for script maybe it is not faster but it is easier use command than check all files.If not device Directory or device /uevent Nothing in pci No information usb The information is filtered and obtained as follows:
cat /sys/class/hwmon/hwmon2/device/uevent
Code: Select all
$ dmesg | grep -i VGA
...
[ 0.000000] fb0: VESA VGA frame buffer device
[ 0.000000] fb: switching to nouveaufb from VESA VGA
...
Code: Select all
$ dmesg | grep -i vga
...
[ 0.466041] fb0: VESA VGA frame buffer device
...
I remember long time ago Ubuntu had problem with GRUB resolution ( maybe in Ubuntu 10.04 )The Linux framebuffer (fbdev) is a graphic hardware-independent abstraction layer to show graphics on a computer monitor, typically on the system console
Code: Select all
... | awk '/driver=/ {print $2}'
With that mindset, don't use AWK because BASH is more than capable of parsing data.mpez0 wrote: ⤴Sun Dec 13, 2020 3:59 pm > gpudriver=`sudo lshw -c video |grep 'driver=' |awk '{ print $2}'`
Don't use grep | awk. Awk is perfectly capable of doing its own filtering of input, viz:
Code: Select all
... | awk '/driver=/ {print $2}'