You are not logged in.
I have a script that fetches multiple entries from a site. I use:
${execi 100 command.sh | awk NR==1}
${execi 100 command.sh | awk NR==2}
${execi 100 command.sh | awk NR==3}
${execi 100 command.sh | awk NR==4}
${execi 100 command.sh | awk NR==5}I have chosen to only show 5 entries to save space. The problem is that sometimes 5 entries don't exist, but instead only 2, or 3. This causes blank lines where usually text would appear.
Is there any way to only show a line if it actually contains content ? Like some kind of 'if' statement ? I checked the conky variables but didn't see anything that might work.
Last edited by f3bruary (2015-06-19 10:23:52)
-f3b
Offline
There are no if statements in the Conky config... so put one in your sh script ![]()
If the output is empty, do nothing. Else, print output.
I believe that should do what you want.
Offline
Oh dear, please do not run that five separate times. The following would do the exact same as what you have with *far* fewer processes, less CPU use, less memory, etc:
${execi 100 command.sh | awk 'NR < 6'}Actually, so would a `head -5` command, but head couldn't be adjusted to do what you want, which would be as follows:
${execi 100 command.sh | awk 'NR < 6 { if ($0) print; }'}But, although I do love awk, it might also be overkill for this. The following might be more efficient:
${execi 100 command.sh | sed -e '/^$/d' -e '6,$d'}"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Oh dear, please do not run that five separate times. The following would do the exact same as what you have with *far* fewer processes, less CPU use, less memory, etc:
${execi 100 command.sh | awk 'NR < 6'}Actually, so would a `head -5` command, but head couldn't be adjusted to do what you want, which would be as follows:
${execi 100 command.sh | awk 'NR < 6 { if ($0) print; }'}But, although I do love awk, it might also be overkill for this. The following might be more efficient:
${execi 100 command.sh | sed -e '/^$/d' -e '6,$d'}
Thanks man that is indeed more efficient. However, I should have been a little more exact in the command I actually use.
${execi 21600 sh ~/.conky/scripts/command.sh event | sed -e '/^$/d' -e '6,$d'}${alignr}${execi 21600 sh ~/.conky/scripts/command.sh date | sed -e '/^$/d' -e '6,$d'}The first command works just fine they way you recommended. The 2nd command however, does not and instead doesn't align to the right but gets underneath the previous one.
That's why I used 5 lines before. The first command would show the first, let's say 'event', then behind it, the 2nd command would show the respective 'date'.
-f3b
Offline
Just for completeness, the awk entry could use pattern matching:
${execi 100 command.sh | awk '/^.+$/ && NR < 6 {print}'}and the sed option doesn't need two scripts and can use quit:
${execi 100 command.sh | sed '/^$/d; 6q'}EDIT: typo
Last edited by skanky (2015-06-15 12:11:23)
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
I found the ${combine} function for conky. It should put 2 command outputs next to each other but it's not working as desired. First of all, using the sed/awk command posted earlier, only the first entry is shown. And second, I can't align the 2nd output to the right (using ${alignr} or ${goto}, it breaks the combine function.
-f3b
Offline
I'd simply builld the whole lot into a script, where you can limit or discard output as you see fit, and simply:
exec cat /tmp/txtlet your script format the output for conky, so that it's all nice & pretty. The added bonus, is that you can avoid tying conky up with the script.
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
The problem is that I can't align the 2 strings for conky except in the conkyrc. If my script output "Event Date" then I cannot split them apart and make sure the date is aligned to the right.
-f3b
Offline
Use the execpi command:
${execpi 100 command.sh}Then in your command.sh do something like this:
#!/bin/bash
event="xxxx"
date="$(date)"
echo -n "${event}\${alignr}${date}"Offline
Use the execpi command:
${execpi 100 command.sh}Then in your command.sh do something like this:
#!/bin/bash event="xxxx" date="$(date)" echo -n "${event}\${alignr}${date}"
Wow thanks a lot man, I just finished coding it up. Works perfectly !
-f3b
Offline