Need help to change format that script creates.

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 to change format that script creates.

Post by Logansfury »

Hello everyone,

Another all nighter on the Linux box lol.

I have the following script:

Code: Select all

${color1}${goto 35}CPU : ${color}${exec sensors  | grep 'temp1' | awk 'NR==1{print $2}'} ${alignr}${color1}GPU : ${color}${exec sensors  | grep 'temp1' | awk 'NR==2{print $2}'}
This outputs the temps of each of my 4 cpu cores, but it does it as a single column of 4 rows of text. I would like please to have this print in 2 columns with 2 items each ie:

Current display:
1
2
3
4

Desired display
1 2
3 4

Can anyone provide an edit?

Thanks for reading,

Logan
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: Need help to change format that script creates.

Post by xenopeek »

You can append a pipe | paste -d$'\t' - - at the end to join odd and even lines, separate them with a tab.

Or an extra pipe | paste -d$'\t' - - | column -t to neatly format it into columns, using only the width for each column as needed. If lines can have different lengths this may work better.

Example:

Code: Select all

$ echo $'+12.0°C\n+24.0°C\n+36.0°C\n+48.0°C'
+12.0°C
+24.0°C
+36.0°C
+48.0°C
$ echo $'+12.0°C\n+24.0°C\n+36.0°C\n+48.0°C' | paste -d$'\t' - -
+12.0°C	+24.0°C
+36.0°C	+48.0°C
$ echo $'+12.0°C\n+24.0°C\n+36.0°C\n+48.0°C' | paste -d$'\t' - - | column -t
+12.0°C  +24.0°C
+36.0°C  +48.0°C
Image
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 to change format that script creates.

Post by Logansfury »

Thank you Xenopeek,

I will try these :)
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 to change format that script creates.

Post by Logansfury »

xenopeek wrote: Wed Feb 07, 2024 9:37 am You can append a pipe | paste -d$'\t' - - at the end to join odd and even lines, separate them with a tab.

Or an extra pipe | paste -d$'\t' - - | column -t to neatly format it into columns, using only the width for each column as needed. If lines can have different lengths this may work better.

Example:

Code: Select all

$ echo $'+12.0°C\n+24.0°C\n+36.0°C\n+48.0°C'
+12.0°C
+24.0°C
+36.0°C
+48.0°C
$ echo $'+12.0°C\n+24.0°C\n+36.0°C\n+48.0°C' | paste -d$'\t' - -
+12.0°C	+24.0°C
+36.0°C	+48.0°C
$ echo $'+12.0°C\n+24.0°C\n+36.0°C\n+48.0°C' | paste -d$'\t' - - | column -t
+12.0°C  +24.0°C
+36.0°C  +48.0°C
I'm afraid this didn't work. I pasted at the end of my code, separated by a space and it printed the 4 lines in one column with the command printed on screen as well.

Here is my script:

Code: Select all

${color1}${goto 35}CPU : ${color} \ ${execp sensors coretemp-isa-0000 -u | grep 'temp[1-4]_input' | awk '{printf "${goto 68}Core %d: %+0.1f°F/%+0.1f°C\n", NR, $2 * 9/5 + 32, $2}'
Is there another way please?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Need help to change format that script creates.

Post by Koentje »

Worked for me!

Code: Select all

$ sensors coretemp-isa-0000 -u | grep 'temp[1-4]_input' | awk '{printf "${goto 68}Core %d: %+0.1fF/%+0.1fC\n", NR, $2 * 9/5 + 32, $2}' | paste -d$'\t' - - | column -t
${goto  68}Core  1:  +141.8F/+61.0C  ${goto  68}Core  2:  +136.4F/+58.0C
${goto  68}Core  3:  +140.0F/+60.0C  ${goto  68}Core  4:  +141.8F/+61.0C
Problem is the ${goto 68}!

PM me your /etc/hwmon file, then i'll fix it..
Image
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 to change format that script creates.

Post by Logansfury »

Koentje wrote: Wed Feb 07, 2024 6:05 pm Worked for me!

Code: Select all

$ sensors coretemp-isa-0000 -u | grep 'temp[1-4]_input' | awk '{printf "${goto 68}Core %d: %+0.1fF/%+0.1fC\n", NR, $2 * 9/5 + 32, $2}' | paste -d$'\t' - - | column -t
${goto  68}Core  1:  +141.8F/+61.0C  ${goto  68}Core  2:  +136.4F/+58.0C
${goto  68}Core  3:  +140.0F/+60.0C  ${goto  68}Core  4:  +141.8F/+61.0C
Problem is the ${goto 68}!

PM me your /etc/hwmon file, then i'll fix it..
putting it together now, stand by and thank you :)
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Need help to change format that script creates.

Post by Koentje »

Ditch these complicated calculations with sensors and execute this script.

Code: Select all

#!/bin/bash

# GET TEMP IN CELCIUS
temp1c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp1_input)/1000 | bc)
temp2c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp2_input)/1000 | bc)
temp3c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp3_input)/1000 | bc)
temp4c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp4_input)/1000 | bc)

# GET TEMP IN FARENHEIT
temp1f=$(echo "1.8*$temp1c+32" | bc)
temp2f=$(echo "1.8*$temp2c+32" | bc)
temp3f=$(echo "1.8*$temp3c+32" | bc)
temp4f=$(echo "1.8*$temp4c+32" | bc)

# SETUP PER LINE
out1="\${goto 100}Core 1: +$temp1f"F/+$temp1c"C"
out2="\${goto 280}Core 2: +$temp2f"F/+$temp2c"C"
out3="\${goto 100}Core 3: +$temp3f"F/+$temp3c"C"
out4="\${goto 280}Core 4: +$temp4f"F/+$temp4c"C"

# PASTE THIS TO CONKY WINDOW
echo "$out1 $out2"
echo "$out3 $out4"
Now you can set it up how you want!
Schermafdruk van 2024-02-07 23-59-42.jpg
Schermafdruk van 2024-02-07 23-59-42.jpg (7.08 KiB) Viewed 545 times
Image
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 to change format that script creates.

Post by Logansfury »

Koentje wrote: Wed Feb 07, 2024 6:56 pm Ditch these complicated calculations with sensors and execute this script.

Code: Select all

#!/bin/bash

# GET TEMP IN CELCIUS
temp1c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp1_input)/1000 | bc)
temp2c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp2_input)/1000 | bc)
temp3c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp3_input)/1000 | bc)
temp4c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp4_input)/1000 | bc)

# GET TEMP IN FARENHEIT
temp1f=$(echo "1.8*$temp1c+32" | bc)
temp2f=$(echo "1.8*$temp2c+32" | bc)
temp3f=$(echo "1.8*$temp3c+32" | bc)
temp4f=$(echo "1.8*$temp4c+32" | bc)

# SETUP PER LINE
out1="\${goto 100}Core 1: +$temp1f"F/+$temp1c"C"
out2="\${goto 280}Core 2: +$temp2f"F/+$temp2c"C"
out3="\${goto 100}Core 3: +$temp3f"F/+$temp3c"C"
out4="\${goto 280}Core 4: +$temp4f"F/+$temp4c"C"

# PASTE THIS TO CONKY WINDOW
echo "$out1 $out2"
echo "$out3 $out4"
Now you can set it up how you want!

Schermafdruk van 2024-02-07 23-59-42.jpg
Far out! Thank you so much, I am just finishing edits on the Bleys Weather Widget, and then I will turn attention to this. Bleys coded the alphabetical direction for me straight in the .lua without any additional files! My display is almost exactly as I want it.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Need help to change format that script creates.

Post by Koentje »

Logansfury wrote: Wed Feb 07, 2024 7:30 pm My display is almost exactly as I want it.
Heard that before.... ;)
Image
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 to change format that script creates.

Post by Logansfury »

Koentje wrote: Wed Feb 07, 2024 7:32 pm
Logansfury wrote: Wed Feb 07, 2024 7:30 pm My display is almost exactly as I want it.
Heard that before.... ;)
I put the blame firmly on Bleys. He makes too many beautiful conky widgets. What the hell is a man to do??
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 to change format that script creates.

Post by Logansfury »

Koentje wrote: Wed Feb 07, 2024 6:56 pm Ditch these complicated calculations with sensors and execute this script.

Code: Select all

#!/bin/bash

# GET TEMP IN CELCIUS
temp1c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp1_input)/1000 | bc)
temp2c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp2_input)/1000 | bc)
temp3c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp3_input)/1000 | bc)
temp4c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp4_input)/1000 | bc)

# GET TEMP IN FARENHEIT
temp1f=$(echo "1.8*$temp1c+32" | bc)
temp2f=$(echo "1.8*$temp2c+32" | bc)
temp3f=$(echo "1.8*$temp3c+32" | bc)
temp4f=$(echo "1.8*$temp4c+32" | bc)

# SETUP PER LINE
out1="\${goto 100}Core 1: +$temp1f"F/+$temp1c"C"
out2="\${goto 280}Core 2: +$temp2f"F/+$temp2c"C"
out3="\${goto 100}Core 3: +$temp3f"F/+$temp3c"C"
out4="\${goto 280}Core 4: +$temp4f"F/+$temp4c"C"

# PASTE THIS TO CONKY WINDOW
echo "$out1 $out2"
echo "$out3 $out4"
Now you can set it up how you want!

Schermafdruk van 2024-02-07 23-59-42.jpg
I'm still loopy from yesterday's ER visit. Lemme make sure my addled brain is getting this. This is a bash script outside of conky that needs to be exec by conky? So I make a conky with an ${exec } line just before the echo lines?

Please be gentle with me if I got this wrong. Sleep has been elusive lately.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Need help to change format that script creates.

Post by Koentje »

Logansfury wrote: Wed Feb 07, 2024 8:25 pm I'm still loopy from yesterday's ER visit. Lemme make sure my addled brain is getting this. This is a bash script outside of conky that needs to be exec by conky? So I make a conky with an ${exec } line just before the echo lines?

Please be gentle with me if I got this wrong. Sleep has been elusive lately.
What was the problem? The sensors line in your conky.
So you replace this line:
${color1}${goto 35}CPU : ${color} \ ${execp sensors coretemp-isa-0000 -u | grep 'temp[1-4]_input' | awk '{printf "${goto 68}Core %d: %+0.1f°F/%+0.1f°C\n", NR, $2 * 9/5 + 32, $2}'

For this one:
${color1}${goto 35}CPU : ${color} ${execp ./script}

Of course ./script is the name of the script.
Image
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 to change format that script creates.

Post by Logansfury »

Koentje wrote: Wed Feb 07, 2024 8:29 pm
Logansfury wrote: Wed Feb 07, 2024 8:25 pm I'm still loopy from yesterday's ER visit. Lemme make sure my addled brain is getting this. This is a bash script outside of conky that needs to be exec by conky? So I make a conky with an ${exec } line just before the echo lines?

Please be gentle with me if I got this wrong. Sleep has been elusive lately.
What was the problem? The sensors line in your conky.
So you replace this line:
${color1}${goto 35}CPU : ${color} \ ${execp sensors coretemp-isa-0000 -u | grep 'temp[1-4]_input' | awk '{printf "${goto 68}Core %d: %+0.1f°F/%+0.1f°C\n", NR, $2 * 9/5 + 32, $2}'

For this one:
${color1}${goto 35}CPU : ${color} ${execp ./script}

Of course ./script is the name of the script.
I named the script cpu_heat.sh

conky:

Code: Select all

${color1}${goto 35}CPU : ${color} ${execp ./home/logansfury/.conky/cpu_heat.sh}
I only got CPU and GPU displayed, none of the values
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Need help to change format that script creates.

Post by Koentje »

What if you run the script on the terminal?
Image
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 to change format that script creates.

Post by Logansfury »

Good Morning Koentje :D

I'm sorry for late response, I slept in very late, I think I needed it after the ER visit the other day.

It's very likely I have done something wrong or mispasted.

Here is the conky script:

Code: Select all

conky.text = [[
${color1}${goto 35}Dangerous Temps: ${alignr}${color0}(${color2}High: 84.0°C${color0}/${color1}Crit: 100.0°C${color0})
${color}${goto 35}CPU : ${execp /home/logansfury/.conky/cpu_heat.sh} 
# SETUP PER LINE
out1="\${goto 100}Core 1: +$temp1f"F/+$temp1c"C"
out2="\${goto 280}Core 2: +$temp2f"F/+$temp2c"C"
out3="\${goto 100}Core 3: +$temp3f"F/+$temp3c"C"
out4="\${goto 280}Core 4: +$temp4f"F/+$temp4c"C"

# PASTE THIS TO CONKY WINDOW
echo "$out1 $out2"
echo "$out3 $out4"

${color1}${goto 35}GPU: ${color0}${execi 10 sensors | grep -i 'edge' | awk '{temp=$2; sub(/.$/,"",temp); printf("%.1f°F/%.1f°C\n", temp*9/5+32, temp)}'}
 ${alignr}${voffset -15}(${color2}High: 90.0°C${color0}/${color1}Crit: 120.0°C${color0})
]]
Here is the output:
Image
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Need help to change format that script creates.

Post by Koentje »

Image
Image
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 to change format that script creates.

Post by Logansfury »

Koentje wrote: Thu Feb 08, 2024 6:12 pm Image
I claim illness and sleep deprivation.

At a guess this doesn't belong in the conky?

Code: Select all

# SETUP PER LINE
out1="\${goto 100}Core 1: +$temp1f"F/+$temp1c"C"
out2="\${goto 280}Core 2: +$temp2f"F/+$temp2c"C"
out3="\${goto 100}Core 3: +$temp3f"F/+$temp3c"C"
out4="\${goto 280}Core 4: +$temp4f"F/+$temp4c"C"
?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Need help to change format that script creates.

Post by Koentje »

Koentje wrote: Wed Feb 07, 2024 6:56 pm Ditch these complicated calculations with sensors and execute this script.

Code: Select all

#!/bin/bash

# GET TEMP IN CELCIUS
temp1c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp1_input)/1000 | bc)
temp2c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp2_input)/1000 | bc)
temp3c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp3_input)/1000 | bc)
temp4c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp4_input)/1000 | bc)

# GET TEMP IN FARENHEIT
temp1f=$(echo "1.8*$temp1c+32" | bc)
temp2f=$(echo "1.8*$temp2c+32" | bc)
temp3f=$(echo "1.8*$temp3c+32" | bc)
temp4f=$(echo "1.8*$temp4c+32" | bc)

# SETUP PER LINE
out1="\${goto 100}Core 1: +$temp1f"F/+$temp1c"C"
out2="\${goto 280}Core 2: +$temp2f"F/+$temp2c"C"
out3="\${goto 100}Core 3: +$temp3f"F/+$temp3c"C"
out4="\${goto 280}Core 4: +$temp4f"F/+$temp4c"C"

# PASTE THIS TO CONKY WINDOW
echo "$out1 $out2"
echo "$out3 $out4"
Put it in a new file, call it cpu-temps.sh and give it execution rights.
In conky add this line on the place you want these temps ${execp ./cpu-temps.sh}
Image
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 to change format that script creates.

Post by Logansfury »

OK I think I am closer to where I should be.

/home/logansfury/.conky/cpu-temps.sh:

Code: Select all

#!/bin/bash

# GET TEMP IN CELCIUS
temp1c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp1_input)/1000 | bc)
temp2c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp2_input)/1000 | bc)
temp3c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp3_input)/1000 | bc)
temp4c=$(echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp4_input)/1000 | bc)

# GET TEMP IN FARENHEIT
temp1f=$(echo "1.8*$temp1c+32" | bc)
temp2f=$(echo "1.8*$temp2c+32" | bc)
temp3f=$(echo "1.8*$temp3c+32" | bc)
temp4f=$(echo "1.8*$temp4c+32" | bc)

# SETUP PER LINE
out1="\${goto 100}Core 1: +$temp1f"F/+$temp1c"C"
out2="\${goto 280}Core 2: +$temp2f"F/+$temp2c"C"
out3="\${goto 100}Core 3: +$temp3f"F/+$temp3c"C"
out4="\${goto 280}Core 4: +$temp4f"F/+$temp4c"C"

# PASTE THIS TO CONKY WINDOW
echo "$out1 $out2"
echo "$out3 $out4"
This has been chmod'ed

temperatures.conf:

Code: Select all

conky.text = [[
${color1}${goto 35}Dangerous Temps: ${alignr}${color0}(${color2}High: 84.0°C${color0}/${color1}Crit: 100.0°C${color0})
${color}${goto 35}CPU : ${execp ./cpu-temps.sh}


${color1}${goto 35}GPU: ${color0}${execi 10 sensors | grep -i 'edge' | awk '{temp=$2; sub(/.$/,"",temp); printf("%.1f°F/%.1f°C\n", temp*9/5+32, temp)}'}
 ${alignr}${voffset -15}(${color2}High: 90.0°C${color0}/${color1}Crit: 120.0°C${color0})
]]
Result:
Image
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Need help to change format that script creates.

Post by Koentje »

Have you tested it on the terminal?
Image
Post Reply

Return to “Compiz, Conky, Docks & Widgets”