So I'm getting to get the CPU core temperature using sensors command.
Inside conky, I wrote
$Core 0 Temp:$alignr${execi 1 sensors | grep 'Core 0' | awk {'print $3'}} $alignr${execibar 1 sensors | grep 'Core 0' | awk {'print $3'}}
Each second I'm running the exact same command sensors | grep 'Core 0' | awk {'print $3'} in two places for exact same output. Is there is a way to hold the output inside a variable and use that variable in place of the commands.
conkydoes not have user variables. What you can do instead is call lua from conky to do this for you. The lua language is usually built-in to conky by default, so you need only put some code in a file, include the file in the conky setup file, and call the function. For example, these shell commands will create a test:In the
myfunction.luafile, we declare a functionmyfunction()(which needs to be prefixedconky_so we can call it from conky). It takes 2 parameters, the name of a variable, and a conky expression. It callsconky_parse()to evaluate the expression, and saves the value in a tablevars, under the name provided by the caller. It then returns the resulting value to the caller. If no expression was given, it will return the previous value.In the
conky.textthe line beginningsetcallsmyfunctionin lua with the arbitrary name of a variable,t, and theexecisensors expression to evaluate, save, and return. The line beginninggetcallsmyfunctionto just get the value.lua_baris similar toexec_bar, but calls a lua function, seeman conky. However, it expects a number without the leading+thatexec_baraccepts, so I've changed theawkto return this, and have added the°Cto the conky text instead.