LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 12-24-2013, 06:20 AM   #1
zarksentinel
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Rep: Reputation: Disabled
(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}
 
Old 12-24-2013, 07:18 AM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,504
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 12-24-2013, 08:24 AM   #3
ondoho
Senior Member
 
Registered: Dec 2013
Distribution: arch linux / crunchbang
Posts: 1,110

Rep: Reputation: 151Reputation: 151
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).
 
Old 12-26-2013, 03:04 AM   #4
zarksentinel
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
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 View Post
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
 
Old 12-26-2013, 03:55 AM   #5
phenixia2003
Member
 
Registered: May 2006
Location: France
Distribution: Slackware
Posts: 295

Rep: Reputation: 166Reputation: 166
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

Last edited by phenixia2003; 12-26-2013 at 04:02 AM.
 
1 members found this post helpful.
Old 12-26-2013, 10:41 AM   #6
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware current(32) (started with 13.37(32))
Posts: 145

Rep: Reputation: 30
Quote:
Originally Posted by phenixia2003 View Post
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 works like a charm.
For me, vertical offset 23 with this font "xftfont Liberarion Mono:size=14"
 
Old 12-26-2013, 11:00 AM   #7
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,504
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by zarksentinel View Post
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.
 
Old 12-27-2013, 01:27 AM   #8
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 3,432

Rep: Reputation: 796Reputation: 796Reputation: 796Reputation: 796Reputation: 796Reputation: 796Reputation: 796
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}...
 
Old 12-27-2013, 03:02 AM   #9
descendant_command
Member
 
Registered: Mar 2012
Posts: 807

Rep: Reputation: 182Reputation: 182
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...
 
Old 12-27-2013, 04:24 AM   #10
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,504
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by descendant_command View Post
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.
 
Old 12-27-2013, 02:24 PM   #11
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 3,432

Rep: Reputation: 796Reputation: 796Reputation: 796Reputation: 796Reputation: 796Reputation: 796Reputation: 796
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
teamviewer "show black screen" and "disable remote input" in x11vnc ? alirezaimi Linux - Networking 0 05-08-2013 06:44 PM
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 6 03-21-2013 10:35 AM
Why do the "£inux" and "PSinux" satirical misspellings even exist?! LOL! Kenny_Strawn General 19 12-09-2010 02:01 PM
Program to "assemble" still-frame pictures into "animated" show Pantherman Linux - General 3 12-24-2009 11:14 PM
X: video drivers "ati" and "fglrx" show same fonts differently simopal6 Linux - Software 7 07-30-2008 02:36 AM


All times are GMT -5. The time now is 04:47 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration