You are not logged in.

#1 2008-12-08 21:42:12

michaelramm
Member
From: Northport, AL USA
Registered: 2008-09-08
Posts: 10
Website

Conky Conditional Statement

Is there a way to make a conky config that will check to see it your wlan card is on/off. When it is on, it should show some set of information that you choose. When it is off, none of that information should be shown.

I like to see:
Link Quality
SSID
Up
Down
Upload
Download
IP Address

I know that conky has if-elseif-endif statements, but I assume that those go through the config once, and then don't go through it again.

I guess that it could be done with an external script as well, but I am no programmer, so I am not sure about that.

Thoughts?

Michael


OpenArch = Dell Dimension 4300 with Arch Linux and Openbox3

Offline

#2 2008-12-08 21:51:23

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Conky Conditional Statement

This is a snip from my .conkyrc smile

${if_existing /proc/net/route wlan0}
   ${color0}Wireless
   ${color0}IP Address:${alignr}${color1}${addr wlan0}
   ${color0}Download:${alignr}${color1}${downspeed wlan0}k/s
   ${color0}Upload:${alignr}${color1}${upspeed wlan0}k/s
   ${color0}Strength:${wireless_link_bar wlan0}
${endif}

Offline

#3 2008-12-08 21:52:48

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Conky Conditional Statement

Another way to do this is to use conky if_up condition -- see man conky for details.

Offline

#4 2008-12-08 22:00:03

michaelramm
Member
From: Northport, AL USA
Registered: 2008-09-08
Posts: 10
Website

Re: Conky Conditional Statement

Here is mine:

NETWORK ${hr 2}
${if_existing /proc/net/route eth0}
${alignc}Wired
     Up: ${upspeed eth0} kb/s ${alignr}${upspeedgraph eth0 8,60 789E2D A7CC5C}
     Down: ${downspeed eth0} kb/s ${alignr}${downspeedgraph eth0 8,60 789E2D A7CC5C}
     Upload: ${alignr}${totalup eth0} 
     Download: ${alignr}${totaldown eth0}
     Local IP: ${alignr}${addr eth0}
${else}
${if_existing /proc/net/route eth1}
${alignc}Wireless
     Signal: ${wireless_link_qual eth1}% ${alignr}${wireless_link_bar 8,60 eth1}
     Attached to:${alignr}${wireless_essid eth1}
     Up: ${upspeed eth1} kb/s ${alignr}${upspeedgraph eth1 8,60 789E2D A7CC5C}
     Down: ${downspeed eth1} kb/s ${alignr}${downspeedgraph eth1 8,60 789E2D A7CC5C}
     Upload: ${alignr}${totalup eth1}
     Download: ${alignr}${totaldown eth1}
     Local IP: ${alignr}${addr eth1}
${endif}

But when I 'Enable Wireless', the Wireless section does not refresh in conky to add it to my screen.

I was looking for more of a realtime monitor of my wireless stats.

Michael


OpenArch = Dell Dimension 4300 with Arch Linux and Openbox3

Offline

#5 2008-12-08 22:02:48

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Conky Conditional Statement

michaelramm wrote:

Here is mine:

NETWORK ${hr 2}
${if_existing /proc/net/route eth0}
${alignc}Wired
     Up: ${upspeed eth0} kb/s ${alignr}${upspeedgraph eth0 8,60 789E2D A7CC5C}
     Down: ${downspeed eth0} kb/s ${alignr}${downspeedgraph eth0 8,60 789E2D A7CC5C}
     Upload: ${alignr}${totalup eth0}  
     Download: ${alignr}${totaldown eth0}
     Local IP: ${alignr}${addr eth0}
${else}
${if_existing /proc/net/route eth1}
${alignc}Wireless
     Signal: ${wireless_link_qual eth1}% ${alignr}${wireless_link_bar 8,60 eth1}
     Attached to:${alignr}${wireless_essid eth1} 
     Up: ${upspeed eth1} kb/s ${alignr}${upspeedgraph eth1 8,60 789E2D A7CC5C}
     Down: ${downspeed eth1} kb/s ${alignr}${downspeedgraph eth1 8,60 789E2D A7CC5C}
     Upload: ${alignr}${totalup eth1}
     Download: ${alignr}${totaldown eth1}
     Local IP: ${alignr}${addr eth1}
${endif}

just an observation

if your first $if_existing is always true (eth0 exists) then the $else condition will never be run.

i'd reverse your statements and you may find it works as you want.

Offline

#6 2008-12-08 22:18:03

michaelramm
Member
From: Northport, AL USA
Registered: 2008-09-08
Posts: 10
Website

Re: Conky Conditional Statement

brisbin33 wrote:
michaelramm wrote:

Here is mine:

NETWORK ${hr 2}
${if_existing /proc/net/route eth0}
${alignc}Wired
     Up: ${upspeed eth0} kb/s ${alignr}${upspeedgraph eth0 8,60 789E2D A7CC5C}
     Down: ${downspeed eth0} kb/s ${alignr}${downspeedgraph eth0 8,60 789E2D A7CC5C}
     Upload: ${alignr}${totalup eth0}  
     Download: ${alignr}${totaldown eth0}
     Local IP: ${alignr}${addr eth0}
[b]${else}[/b]
${if_existing /proc/net/route eth1}
${alignc}Wireless
     Signal: ${wireless_link_qual eth1}% ${alignr}${wireless_link_bar 8,60 eth1}
     Attached to:${alignr}${wireless_essid eth1} 
     Up: ${upspeed eth1} kb/s ${alignr}${upspeedgraph eth1 8,60 789E2D A7CC5C}
     Down: ${downspeed eth1} kb/s ${alignr}${downspeedgraph eth1 8,60 789E2D A7CC5C}
     Upload: ${alignr}${totalup eth1}
     Download: ${alignr}${totaldown eth1}
     Local IP: ${alignr}${addr eth1}
${endif}

just an observation

if your first $if_existing is always true (eth0 exists) then the $else condition will never be run.

i'd reverse your statements and you may find it works as you want.

Thanks for the insight!

I took out the else that is bolded above, and it is rocking along just how I want it to. Wireless section goes away when I turn off wireless and it reappears when I turn it on!

Thanks,
Michael


OpenArch = Dell Dimension 4300 with Arch Linux and Openbox3

Offline

#7 2008-12-08 22:44:28

xisal
Member
Registered: 2007-10-19
Posts: 24

Re: Conky Conditional Statement

Another one:

${if_up wlan0}
${color 9AB7DC}Wireless: 
${color a4a4a4}${wireless_essid wlan0} $alignr(${wireless_link_qual_perc wlan0}%)

${color 9AB7DC}Up:${color a4a4a4}${alignr}${upspeed wlan0}KB/s
${color 668ABF}${upspeedgraph wlan0 10,85 668ABF 9AB7DC}
${color 9AB7DC}Total: ${color a4a4a4}${totalup wlan0}

${color 9AB7DC}Down:${color a4a4a4}${alignr}${downspeed wlan0}KB/s
${color 668ABF}${downspeedgraph wlan0 10,85 668ABF 9AB7DC}
${color 9AB7DC}Total: ${color a4a4a4}${totaldown wlan0}
${endif}

${if_up eth0}
${color 9AB7DC}Network:
${color 9AB7DC}Up:${color a4a4a4}${alignr}${upspeed eth0}KB/s
${color 668ABF}${upspeedgraph eth0 10,85 668ABF 9AB7DC}
${color 9AB7DC}Total: ${color a4a4a4}${totalup eth0}

${color 9AB7DC}Down:${color a4a4a4}${alignr}${downspeed eth0}KB/s
${color 668ABF}${downspeedgraph eth0 10,85 668ABF 9AB7DC}
${color 9AB7DC}Total: ${color a4a4a4}${totaldown eth0}
${endif}

Offline

#8 2008-12-08 22:46:53

Shapeshifter
Member
Registered: 2008-03-11
Posts: 230

Re: Conky Conditional Statement

and another (shortened) one, using the kill switch condition:

Wireless ESSID: ${if_existing /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/rfkill:rfkill0/state 2}Kill switch enabled${endif}${if_existing /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/rfkill:rfkill0/state 1}${wireless_essid wlan0}${alignr}${color}Link Quality:${color #B3B3B3} ${wireless_link_qual wlan0}${endif}

Prints "Kill switch enabled" if rfkill is 2, and prints "some_essid $alignr Link Quality: some_quality" when rfkill is 1.
Though I think I messed something up with the numbers as I switched from ipw to iwl. Haven't taken care of it since.

Last edited by Shapeshifter (2008-12-08 22:48:52)

Offline

#9 2008-12-08 22:54:34

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Conky Conditional Statement

michaelramm wrote:

I took out the else that is bolded above, and it is rocking along just how I want it to

glad i could help, you didn't really have to remove the else; if it were me i'd just reverse them like this

${if_existing /wireless/path}

--wireless info--

$else
${if_existing /wired/path}

--wired info--

$endif

that way you get wireless info only when your wireless and wired info only if your wired. 

i'm glad you got me thinking on this; i might implement a similar amarok/mpd if/else switch for my "Now Playing" section in my conky smile

Offline

#10 2008-12-11 23:49:01

michaelramm
Member
From: Northport, AL USA
Registered: 2008-09-08
Posts: 10
Website

Re: Conky Conditional Statement

brisbin33 wrote:
michaelramm wrote:

I took out the else that is bolded above, and it is rocking along just how I want it to

glad i could help, you didn't really have to remove the else; if it were me i'd just reverse them like this

${if_existing /wireless/path}

--wireless info--

$else
${if_existing /wired/path}

--wired info--

$endif

that way you get wireless info only when your wireless and wired info only if your wired. 

i'm glad you got me thinking on this; i might implement a similar amarok/mpd if/else switch for my "Now Playing" section in my conky smile

Once again, you are right. I hooked up to a wlan without a lan, and the bottom of the graph was gone. So I swapped the wlan and lan stmts and we are cooking with gas now!

Once again, my thanks to you!

Michael


OpenArch = Dell Dimension 4300 with Arch Linux and Openbox3

Offline

Board footer

Powered by FluxBB