need help with script syntax please

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

need help with script syntax please

Post by Logansfury »

Hello all,

I am trying to read from an inxi -G command. The line being read is:

unloaded: fbdev,modesetting,vesa gpu: amdgpu resolution: 1: 2560x1440~60Hz

I am trying to get conky to print "amdgpu" from the above. this isn't working: ${exec inxi -G | grep 'gpu:' | awk '{print $2}'} and gives a blank or empty result.

What would be the proper syntax for the above command please?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: need help with script syntax please

Post by AndyMH »

I always run into trouble when I use awk, try cut:

Code: Select all

andy@M720 ~ $ inxi -G | grep gpu
    unloaded: fbdev,vesa gpu: i915 resolution: 2560x1080~60Hz
andy@M720 ~ $ inxi -G | grep gpu | cut -f3 -d:
 i915 resolution
andy@M720 ~ $ inxi -G | grep gpu | cut -f3 -d: | cut -f2 -d\ 
i915
Note there is a space after \ in -d\ .
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: need help with script syntax please

Post by Logansfury »

AndyMH wrote: Mon Mar 25, 2024 8:38 am I always run into trouble when I use awk, try cut:

Code: Select all

andy@M720 ~ $ inxi -G | grep gpu
    unloaded: fbdev,vesa gpu: i915 resolution: 2560x1080~60Hz
andy@M720 ~ $ inxi -G | grep gpu | cut -f3 -d:
 i915 resolution
andy@M720 ~ $ inxi -G | grep gpu | cut -f3 -d: | cut -f2 -d\ 
i915
Note there is a space after \ in -d\ .
Hello Andy,

Thank you for joining the thread :)

Here is what my 21.3 Mint returned the commands as:

Code: Select all

logansfury@OptiPlex-5040:~$ inxi -G | grep gpu | cut -f3 -d:
 amdgpu
 X.Org v
 amdgpu resolution
logansfury@OptiPlex-5040:~$ inxi -G | grep gpu | cut -f3 -d: | cut -f2 -d\ 
amdgpu
X.Org
amdgpu
I just tried on the net to get code for just the top line. I found this:

Code: Select all

logansfury@OptiPlex-5040:~$ inxi -G | grep gpu | cut -f3 -d: | head -n1
 amdgpu
However when converted for conky ${exec inxi -G | grep gpu | cut -f3 -d: | head -n1}

It spews out the entirety of the line containing gpu.

How would you edit to limit the output to just the top line?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: need help with script syntax please

Post by AndyMH »

Code: Select all

unloaded: fbdev,modesetting,vesa gpu: amdgpu resolution: 1: 2560x1440~60Hz
   f1   :           f2              :        f3        :     f4
so

Code: Select all

inxi -G | grep gpu | cut -f3 -d:
should just return

Code: Select all

 amdgpu resolution
which you can use cut on again using space as a delimiter. So something odd is going on in your inxi output. Try it step by step to figure out what, first just inxi, then with grep and so on.

If conky doesn't like it, put it in a script:

Code: Select all

#!/usr/bin/bash
inxi -G | grep gpu | cut -f3 -d: | cut -f2 -d\ 
make the script executable and run that with execi in conky. Don't forget there is a space after -d\.

There is probably a more elegant way with awk or sed, but you are asking the wrong person.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: need help with script syntax please

Post by Logansfury »

AndyMH wrote: Mon Mar 25, 2024 10:50 am

Code: Select all

unloaded: fbdev,modesetting,vesa gpu: amdgpu resolution: 1: 2560x1440~60Hz
   f1   :           f2              :        f3        :     f4
so

Code: Select all

inxi -G | grep gpu | cut -f3 -d:
should just return

Code: Select all

 amdgpu resolution
which you can use cut on again using space as a delimiter. So something odd is going on in your inxi output. Try it step by step to figure out what, first just inxi, then with grep and so on.

If conky doesn't like it, put it in a script:

Code: Select all

#!/usr/bin/bash
inxi -G | grep gpu | cut -f3 -d: | cut -f2 -d\ 
make the script executable and run that with execi in conky. Don't forget there is a space after -d\.

There is probably a more elegant way with awk or sed, but you are asking the wrong person.
Far out, thank you Andy :)

"Put it in a script" Koentje is going to hurl something at my skull for not thinking of this myself, he just taught me how to call bash scripts from conky and I used it for my millimeter to inches routine to display physical monitor screen size in my display conky widget >.<

Anyhow, going to work with what you gave me then script a bash if necessary.

Have a great day!
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: need help with script syntax please

Post by Logansfury »

Well this makes no sense >.<

I made a bash script:

driver.sh

Code: Select all

#!/bin/bash


inxi -G | grep gpu | cut -f3 -d: | head -n1
In terminal its perfect:

Code: Select all

logansfury@OptiPlex-5040:~/.conky/Minimalis Conky$ ./driver.sh
 amdgpu
but in conky, executed with ${exec ./driver.sh} it outputs the entire line along with strange characters my font doesn't recognize.

It looks like I'm going to need a command line script that I can run directly in conky.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
Post Reply

Return to “Compiz, Conky, Docks & Widgets”