You are not logged in.

#1 2023-05-09 08:25:02

d066y
Member
Registered: 2023-04-23
Posts: 13

SOLVED | Conky Script - ERROR: Cannot fetch

Hello All,

I am not a good developer and trying to use Conky. Followed up this document: https://wiki.archlinux.org/title/Conky/Tips_and_tricks

Prepared a simple Lua script; updates.lua:

conky.config = {
    alignment = 'top_right',
    background = false,
    double_buffer = true,
    out_to_console = false,
    stippled_borders = 2,
    border_outer_margin = 20,
    border_width = 1,
    max_user_text = 16384,

    color1 = 'CCAB8D',
    
    default_color = 'white',
    default_outline_color = 'white',
    default_shade_color = 'white',

    draw_borders = false,
    draw_outline = false,
    draw_shades = false,

    gap_x = 600,
    gap_y = 20,
    
    own_window = true,
    own_window_type = 'desktop', 
    own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
    own_window_transparent = true,
    
    use_xft = true,
    xftalpha = 0.8,
    font = 'Roboto Mono:size=10',
};


conky.text = [[
${color1}Updates
$hr
${color1}Total Packages:  ${color}${execi 600 checkupdates | wc -l}
${color}${execi 600 checkupdates | awk 'NR<=50'}
]];

It provides an error:

conky -c /home/d066y/.conky/myconky/updates.conf

conky: desktop window (6400003) is subwindow of root window (21c)
conky: window type - desktop
conky: drawing to created window (0x8a00001)
conky: drawing to double buffer
==> ERROR: Cannot fetch updates

It shows one of them at a time but not both. If I use just one of them in the script, it works. But not together.

I know it is not critical, but just annoying.

P.S: I have just realized if I stop and start it a few times, it works too. But it does not work when I reboot the computer. I need to stop and start it a few times.

Last edited by d066y (2023-05-09 15:06:27)

Offline

#2 2023-05-09 12:56:35

Morlock
Member
Registered: 2022-06-20
Posts: 14

Re: SOLVED | Conky Script - ERROR: Cannot fetch

Try:

 ${color}${execi 3600 checkupdates | awk 'NR<=50'} 

Offline

#3 2023-05-09 12:58:12

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,337

Re: SOLVED | Conky Script - ERROR: Cannot fetch

checkupdates is rather slow and requires network IO, I assume you also run into some quota because of the double-invocation.

Try

…
${color1}Total Packages:  ${color}${execi 600 checkupdates | tee >(head -50) | wc -l}
…

But since this is extended bash syntax and I'm not sure conky will execute that "right", you might have to

execi 600 bash -c 'checkupdates | tee >(head -50) | wc -l'

instead.

The alternative approach would be a script that downloads the result in a temporary file *once* and use that file multiple times (eg. if you want different colors or fonts)

Offline

#4 2023-05-09 13:47:04

d066y
Member
Registered: 2023-04-23
Posts: 13

Re: SOLVED | Conky Script - ERROR: Cannot fetch

@Morlock
I tried a long waiting before, and it didn`t work.

@seth
Both options provide the total number but not the list. But no fetch error because I run the command just once. And as you stated, it hits the quota.

Never mind, I need the see update packages. The number is irrelevant.

Thanks anyway

Offline

#5 2023-05-09 13:49:46

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: SOLVED | Conky Script - ERROR: Cannot fetch

You could do this with a single awk script:

${color1}Total Packages:  ${color}${execi 600 checkupdates | awk 'NR<=50{lines[NR]=$0} END{print NR;for(i in lines)print lines[i]}'}

Putting the total at the end would be simpler (no need for the lines array). With execpi you can have the script output ${color} things as well.

Offline

#6 2023-05-09 14:03:14

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,471
Website

Re: SOLVED | Conky Script - ERROR: Cannot fetch

Sed would be much simpler and a single process:

checkupdates | sed -n '1,50p;$='

Oops, if you want the total packages at the top:

${color1}Total Packages:  ${color}${execi 600 checkupdates | sed -n '1h;2,50H;${=;g;p}'}

busybox sed is better ... it works fine without any of those semicolons ( '1h2,50H${=gp}' ).  Gnu's sed has semi-colon cancer.

Last edited by Trilby (2023-05-09 14:15:07)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2023-05-09 15:06:09

d066y
Member
Registered: 2023-04-23
Posts: 13

Re: SOLVED | Conky Script - ERROR: Cannot fetch

${color1}Total Packages:  ${color}${execi 600 checkupdates | awk 'NR<=50{lines[NR]=$0} END{print NR;for(i in lines)print lines[i]}'}

This works flawlessly. Thank you @Raynman

Offline

#8 2023-05-09 15:09:29

d066y
Member
Registered: 2023-04-23
Posts: 13

Re: SOLVED | Conky Script - ERROR: Cannot fetch

${color1}Total Packages:  ${color}${execi 600 checkupdates | sed -n '1h;2,50H;${=;g;p}'}

And this one too (:  Thank you @Trilby

Thank you all guys

Offline

#9 2023-05-09 16:58:38

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,471
Website

Re: SOLVED | Conky Script - ERROR: Cannot fetch

FYI awk can also do it without the loop; this basically translates the approach used in sed into awk:

checkupdates | awk 'NR < 51 { a=a"\n"$0 } END { print NR, a; }'

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB