LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   (Conky) How to not show "if_existing" if it's not exist (http://www.linuxquestions.org/questions/slackware-14/conky-how-to-not-show-if_existing-if-its-not-exist-4175489033/)

zarksentinel 12-24-2013 06:20 AM

(Conky) How to not show "if_existing" if it's not exist
 
Hi all,

Im running on slackware 14.0.Im having some issue on conky. I use a few "if_existing" statement in the configuration file to display the network interface information if conky detect eth0/eth1/eth2/eth3.

The problem comes when the system only detect one interface. Conky display lots of blank space for the un-detected interface. (Assume it only display eth0 information and show eth1,eth2 and eth3 as blank space)

Question: Is there any way to remove those blank space/line? As in, take out the blank line/space if it doesn't detect the interface. I read up the manual page, it seems i can't find any argument to group it up.

Advice needed. Thanks in advance.

Screenshot:

[URL="http://s23.postimg.org/k7umnh9e3/image.jpg"]


Code:

alignment bottom_left
background no
border_width 1
cpu_avg_samples 2
default_color blue
default_outline_color blue
default_shade_color blue
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
xftfont arial
gap_x 5
gap_y 60
minimum_size 5 5
maximum_width 400
net_avg_samples 2
no_buffers yes
out_to_console no
own_window yes
own_window_class System Monitor
own_window_colour white
own_window_type normal
stippled_borders 0
update_interval 3.0
uppercase no
use_spacer no
use_xft yes

TEXT
${color darkblue}$nodename

${color red}Server IP:
${if_existing /proc/net/route eth0}${color darkgreen}eth0 ${color blue}${addr eth0} ${endif}
${if_existing /proc/net/route eth1}${color darkgreen}eth1 ${color blue}${addr eth1} ${endif}
${if_existing /proc/net/route eth2}${color darkgreen}eth2 ${color blue}${addr eth2} ${endif}
${if_existing /proc/net/route eth3}${color darkgreen}eth3 ${color blue}${addr eth3} ${endif}

${color black}Uptime:    $color $uptime

${color red}Memory:
${color black}RAM $color $alignc $mem / $memmax $alignr $memperc%
$membar

${color red}File Systems:
${color black} /    $color${fs_used /}/${fs_size /}
${fs_used_perc /}% ${fs_bar 8 /}
${color black} /var $color${fs_used /var}/${fs_size /var}
${fs_used_perc /var}% ${fs_bar 8 /var}
${color black} /mnt $color${fs_used /mnt}/${fs_size /mnt}
${fs_used_perc /mnt}% ${fs_bar 8 /mnt}

${color red}Networking:
${if_existing /proc/net/route eth0}${color darkgreen}eth0 ${color black}Up:$color ${upspeed eth0} kb/s  ${color black}Total: $color ${totalup eth0} ${endif}
${if_existing /proc/net/route eth0}${color darkgreen}eth0 ${color black}Down:$color ${downspeed eth0} kb/s  Total: ${totaldown eth0} ${endif}

${if_existing /proc/net/route eth1}${color darkgreen}eth1 ${color black}Up:$color ${upspeed eth1} kb/s  ${color black}Total: $color ${totalup eth1} ${endif}
${if_existing /proc/net/route eth1}${color darkgreen}eth1 ${color black}Down:$color ${downspeed eth1} kb/s  Total: ${totaldown eth1} ${endif}

${if_existing /proc/net/route eth2}${color darkgreen}eth2 ${color black}Up:$color ${upspeed eth2} kb/s  ${color black}Total: $color ${totalup eth2} ${endif}
${if_existing /proc/net/route eth2}${color darkgreen}eth2 ${color black}Down:$color ${downspeed eth2} kb/s  Total: ${totaldown eth2} ${endif}

${if_existing /proc/net/route eth3}${color darkgreen}eth3 ${color black}Up:$color ${upspeed eth3} kb/s  ${color black}Total: $color ${totalup eth3} ${endif}
${if_existing /proc/net/route eth3}${color darkgreen}eth3 ${color black}Down:$color ${downspeed eth3} kb/s  Total: ${totaldown eth3} ${endif}


Habitual 12-24-2013 07:18 AM

if
then
else
endif

works for conky also, I used it thusly:
Code:

${if_mounted /media/flash}${goto 600}${color red}USB$color is ${fs_free_perc /media/flash/}% Free$color${else}${color red}USB Not Mounted$color${endif}
but I never tried with multiple if statements.
If this doesn't provide enough incentive, maybe I'll have a look at it for Christmas, or the day after.

http://conky.pitstop.free.fr/wiki/in...ments_%28en%29

ondoho 12-24-2013 08:24 AM

if you add a new line (= press enter) in conkyrc's TEXT section, it will be displayed as such.
if you don't want spaghetticode, you can use \ at the end of each line (except where needed).

zarksentinel 12-26-2013 03:04 AM

Quote:

Originally Posted by Habitual (Post 5086379)
if
then
else
endif

works for conky also, I used it thusly:
Code:

${if_mounted /media/flash}${goto 600}${color red}USB$color is ${fs_free_perc /media/flash/}% Free$color${else}${color red}USB Not Mounted$color${endif}
but I never tried with multiple if statements.
If this doesn't provide enough incentive, maybe I'll have a look at it for Christmas, or the day after.

http://conky.pitstop.free.fr/wiki/in...ments_%28en%29

hmm, i don't want it to display any error message if it doesn't detect the adapter... thanks for your advice :)

Quote:

Originally Posted by ondoho (Post 5086394)
if you add a new line (= press enter) in conkyrc's TEXT section, it will be displayed as such.
if you don't want spaghetticode, you can use \ at the end of each line (except where needed).

i see. any coding for me to refer for this kind of issue? the \ doesn't work as i want too. :( thanks for your advice :)

phenixia2003 12-26-2013 03:55 AM

Hello,

AFAIK, the only way to do that, is to have only one line of code (use \ for better readability), and use goto/voffset to move to the next line when required:

Code:

${color red}Server IP:\
${if_existing /proc/net/route eth0}${goto 8}${voffset 15}${color darkgreen}eth0 ${color blue}${addr eth0} ${endif}\
${if_existing /proc/net/route eth1}${goto 8}${voffset 15}${color darkgreen}eth1 ${color blue}${addr eth1} ${endif}\
${if_existing /proc/net/route eth2}${goto 8}${voffset 15}${color darkgreen}eth2 ${color blue}${addr eth2} ${endif}\
${if_existing /proc/net/route eth3}${goto 8}${voffset 15}${color darkgreen}eth3 ${color blue}${addr eth3} ${endif}

you might have to change the voffset value according to the used font.

Hope this helps.

Greetings.


--
SeB

Paulo2 12-26-2013 10:41 AM

Quote:

Originally Posted by phenixia2003 (Post 5087085)
Hello,

AFAIK, the only way to do that, is to have only one line of code (use \ for better readability), and use goto/voffset to move to the next line when required:

Code:

${color red}Server IP:\
${if_existing /proc/net/route eth0}${goto 8}${voffset 15}${color darkgreen}eth0 ${color blue}${addr eth0} ${endif}\
${if_existing /proc/net/route eth1}${goto 8}${voffset 15}${color darkgreen}eth1 ${color blue}${addr eth1} ${endif}\
${if_existing /proc/net/route eth2}${goto 8}${voffset 15}${color darkgreen}eth2 ${color blue}${addr eth2} ${endif}\
${if_existing /proc/net/route eth3}${goto 8}${voffset 15}${color darkgreen}eth3 ${color blue}${addr eth3} ${endif}

you might have to change the voffset value according to the used font.

Hope this helps.

Greetings.


--
SeB

Thanks :hattip: works like a charm.
For me, vertical offset 23 with this font "xftfont Liberarion Mono:size=14"

Habitual 12-26-2013 11:00 AM

Quote:

Originally Posted by zarksentinel (Post 5087066)
hmm, i don't want it to display any error message if it doesn't detect the adapter... thanks for your advice :)

try something like:
Code:

${color red}Networking:
${if_existing /proc/net/route eth0}${color darkgreen}eth0 ${color black}Up:$color ${upspeed eth0} kb/s  ${color black}Total: $color ${totalup eth0}
${/proc/net/route eth0}${color darkgreen}eth0 ${color black}Down:$color ${downspeed eth0} kb/s  Total: ${totaldown eth0} ${endif}
else
${if_existing /proc/net/route eth1}${color darkgreen}eth1 ${color black}Up:$color ${upspeed eth1} kb/s  ${color black}Total: $color ${totalup eth1}
${/proc/net/route eth1}${color darkgreen}eth1 ${color black}Down:$color ${downspeed eth1} kb/s  Total: ${totaldown eth1} ${endif}
else
${if_existing /proc/net/route eth2}${color darkgreen}eth2 ${color black}Up:$color ${upspeed eth2} kb/s  ${color black}Total: $color ${totalup eth2}
${/proc/net/route eth2}${color darkgreen}eth2 ${color black}Down:$color ${downspeed eth2} kb/s  Total: ${totaldown eth2} ${endif}
else
${if_existing /proc/net/route eth3}${color darkgreen}eth3 ${color black}Up:$color ${upspeed eth3} kb/s  ${color black}Total: $color ${totalup eth3}
${/proc/net/route eth3}${color darkgreen}eth3 ${color black}Down:$color ${downspeed eth3} kb/s  Total: ${totaldown eth3} ${endif}

Stolen from
"Notice the $endif at the end of the line – that’s how we close the $if_existing statement so that only the information between the two is conditional on the conditions being met"

There is NO "then" just
Code:

if
else
endif

sorry about that.

You won't need the second if_existing for each adapter as the first if_existing would include it, if it exists.

273 12-27-2013 01:27 AM

I think I did something similar by putting the ${endif} after the line feed, so something like:
Code:

${if_existing /proc/net/route eth0}${color darkgreen}eth0 ${color black}Up:$color ${upspeed eth0} kb/s  ${color black}Total: $color ${totalup eth0}
${color darkgreen}eth0 ${color black}Down:$color ${downspeed eth0} kb/s  Total: ${totaldown eth0}
${endif}${if_existing /proc/net/route eth1}${color darkgreen}eth1 ${color black}Up:$color ${upspeed eth1} kb/s  ${color black}Total: $color ${totalup eth1}
${color darkgreen}eth1 ${color black}Down:$color ${downspeed eth1} kb/s  Total: ${totaldown eth1}
${endif}...


descendant_command 12-27-2013 03:02 AM

My nasty hack was to append the "if_existing" to the end of the PREVIOUS line, with the code to be executed on it's own line, including the endif and the next if.
That way, if the condition was true, it got a line-feed, if not, it didn't.

But now, after a quick facepalm, I'm trying to figure out where to put a load of \'s so it makes sense to read again... :D

Habitual 12-27-2013 04:24 AM

Quote:

Originally Posted by descendant_command (Post 5087496)
My nasty hack was to append the "if_existing"...

Isn't that was conky is all about? Hacks? ;)
I'd just write a shell script and have conky call that, if it were me.

273 12-27-2013 02:24 PM

That's not a hack at all, it's just using the formatting language as it is suppose to be used. The "if_existing...endif" blocks encompass all that will be shown should that condition be true and that includes any whitespace or line feeds. How else do you expect conky to know whether you want a line feed or not without you specifying it?
You were also, in my opinion, using too many "if_existing" blocks are you only need one per condition not one per line of text.


All times are GMT -5. The time now is 05:49 AM.