Is there a way to loop in conky? For example, I have my .conky script that displays cpu load, however, it has to be reconfigured when I move to another machine. A trivial script like

sudo grep "processor" /proc/cpuinfo | wc -l

gives information about the core count and maybe used in a loop like

${cpu cpu{1}}

I am not a conky/lua expert, so there may be a better way, but this works. You need to create a lua script in, say, file ~/mylua.lua containing

local file = io.popen("grep -c processor /proc/cpuinfo")
local numcpus = file:read("*n")
listcpus = ""
for i = 1,numcpus
do  listcpus = listcpus.."${cpu cpu"..tostring(i).."} "

function conky_mycpus()
 return listcpus

and then in your ~/.conkyrc you can add at the start the line

lua_load ~/mylua.lua

and at the place where you want to have the cpu values, the line

${lua_parse conky_mycpus}

When conky starts the lua script will be run and the variable listcpus will end up being an appropriate string like "${cpu cpu1} ${cpu cpu2}", depending on the number of processors found by grep.

  • any idea why this is occurring execution failed: attempt to call a nil value? – sitilge Oct 1 '16 at 16:20
  • I tried this on a fedora 22 and debian jessie with conky version 1.9 without any errors. You might try looking for debug info with conky -DD. – meuh Oct 1 '16 at 16:58
  • No additional debug info provided when using -DD. conky version is 1.10, running arch + kernel – sitilge Oct 1 '16 at 19:25
  • 1.10 seems to have been a major change with some incompatibilities. Check here for some suggestions. It says the lua api has not changed, but the .conkyrc file has. – meuh Oct 1 '16 at 19:30
  • Yes, but it is smart enough to fallback to old syntax (at least in my case). – sitilge Oct 1 '16 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.