Walkero

web developer, Drupal follower, Docker ninja, JS explorer, PHP believer, Amiga enthusiast, truth seeker, parent & husband... at least for now...

Yesterday I created a new Conky script for my laptop I use for everyday work, running Ubuntu 12.10 with Mate. The image at the left shows how it looks like.

The weather script is based on Yahoo weather API, which is totally free. The script I use is based on the Google Now-Inspired Conky Theme found at OMGUbuntu website. The script retrieves the Weather information and shows them at the Conky. Although I like the default theme weather icons of the above theme, I wanted to make it look like StormCloud.

The StormCloud app uses the Climacons fonts, which is created by Adam Whitcroft and distributed by his Climacons website. Download this font file and copy the Climacons.ttf at your home directory, under the “.fonts” directory. If this folder doesn’t exist, then create it. After that, open a terminal and run the following command, which updates the font caching of your system.

$ sudo fc-cache -fv

Also, I created a small bash script that gets the weather condition code as a parameter, and returns the character that should be typed using the Climacons font. Below you can see the code of this bash file. Copy and paste it inside a text file called weather_font. Don’t forget to make this script executable.

#!/bin/bash
# weather_font v1.0 (2013-05-15)
# Created by George Sokianos                       

case "$1" in
1) echo "("  ;;
2) echo "z"  ;;
3) echo "("  ;;
4) echo "z"  ;;
5) echo "z"  ;;
6) echo "e"  ;;
7) echo "e"  ;;
8) echo "o"  ;;
9) echo "3"  ;;
10) echo "3"  ;;
11) echo "9"  ;;
12) echo "9"  ;;
13) echo "9"  ;;
14) echo "o"  ;;
15) echo "o"  ;;
16) echo "o"  ;;
17) echo "0"  ;;
18) echo "e"  ;;
19) echo "e"  ;;
20) echo "s"  ;;
21) echo "s"  ;;
22) echo "s"  ;;
23) echo "s"  ;;
24) echo "l"  ;;
25) echo "l"  ;;
26) echo "\`"  ;;
27) echo "\`"  ;;
28) echo "2"  ;;
29) echo "1"  ;;
30) echo "2"  ;;
31) echo "1"  ;;
32) echo "/"  ;;
33) echo "v"  ;;
34) echo "/"  ;;
35) echo "v"  ;;
36) echo "e"  ;;
37) echo "v"  ;;
38) echo "z"  ;;
39) echo "z"  ;;
40) echo "z"  ;;
41) echo "3"  ;;
42) echo "o"  ;;
43) echo "o"  ;;
44) echo "o"  ;;
45) echo "\`"  ;;
46) echo "z"  ;;
47) echo "o"  ;;
48) echo "z"  ;;
49)   echo "\`"  ;;
esac

The rest info that my Conky script shows is based on the basic commands of it. You can find information about the used commands at Conky variables and Conky config settings.

At the network section of the Conky you will see that there is my current public IP. This is feasible by accessing the whatsmyip website.

Below you will find my whole Conky script, for you to use. Copy and paste it in a text file and save it as .conkyrc.

# Conky settings #
background no
update_interval 1
double_buffer yes
no_buffers yes

# Window specifications #
own_window yes
own_window_type normal
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
own_window_title 
own_window_argb_visual yes
own_window_argb_value 180
own_window_transparent no

minimum_size 250
minimum_height 300

# Alignment #
alignment top_right
gap_x 0
gap_y 0

border_inner_margin 10
border_outer_margin 0

# Graphics settings #
draw_shades yes
draw_outline no
draw_borders no
draw_graph_borders no

# Text settings #
use_xft yes
xftalpha 0
xftfont Open Sans Light:size=9

override_utf8_locale yes

imlib_cache_size 0

# Color scheme #
own_window_colour 000000
default_color DCDCDC
color1 00BFFF
color2 D789FF
color3 b2f433
color4 fcff35
color5 e22f91
color6 AAAAAA
color7 484848
color8 00BFFF
default_shade_color 1d1d1d

TEXT
###############
# - WEATHER - #
###############
${execi 300 curl -s "http://weather.yahooapis.com/forecastrss?w=24544198&u=c" -o ~/.cache/weather.xml}${font Open Sans Light:size=15}${execi 300 grep "yweather:location" ~/.cache/weather.xml | grep -o "city=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*"}, ${execi 300 grep "yweather:location" ~/.cache/weather.xml | grep -o "country=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*"}${font}
${font Climacons:size=90,weight:normal}${execi 300 sh ~/.conky/myconky/weather_font $(grep "yweather:condition" ~/.cache/weather.xml | grep -o "code=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*")}${font}${voffset -75}
${goto 120}${execi 300 grep "yweather:condition" ~/.cache/weather.xml | grep -o "text=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*"}${voffset 0}
${font Open Sans Light:size=45}${goto 120}${execi 300 grep "yweather:condition" ~/.cache/weather.xml | grep -o "temp=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*"}°${font} 
${goto 120}Wind: ${color6}${execi 300 grep "yweather:wind" ~/.cache/weather.xml | grep -o "speed=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*"} ${execi 300 grep "yweather:units" ~/.cache/weather.xml | grep -o "speed=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*"}${color}${font}
${voffset 5}${font Climacons:size=60}${execi 300 sh ~/.conky/myconky/weather_font $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "code=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | head -n2 | tail -n1)}${goto 130}${execi 300 sh ~/.conky/myconky/weather_font $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "code=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | head -n3 | tail -n1)}${font}${voffset -35}
${goto 80}${execi 300 grep "yweather:forecast" ~/.cache/weather.xml | grep -o "day=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | head -n2 | tail -n1}${goto 200}${execi 300 grep "yweather:forecast" ~/.cache/weather.xml | grep -o "day=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | head -n3 | tail -n1}
${goto 80}${execi 300 grep "yweather:forecast" ~/.cache/weather.xml | grep -o "high=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | head -n2 | tail -n1}° ${color6}${execi 300 grep "yweather:forecast" ~/.cache/weather.xml | grep -o "low=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | head -n1}°${color}${goto 200}${execi 300 grep "yweather:forecast" ~/.cache/weather.xml | grep -o "high=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | head -n3 | tail -n1}° ${color6}${execi 300 grep "yweather:forecast" ~/.cache/weather.xml | grep -o "low=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | tail -n1}°${color}${voffset 10}
${color7}${hr}${color}  
################
# - GFX CARD - #
################
${color1}GPU: ${color3}${execi 1000 lspci | grep NVIDIA | awk '{print $8,$9,$10}' | cut -f2 -d"[" | cut -f1 -d"]"} ${color2} ${execi 30 nvidia-settings -t -q gpucoretemp}°C ${color} ${execi 30 nvidia-settings -t -q GPUCurrentProcessorClockFreqs}Mhz${color}
##################
# - CPU GRAPHS - #
##################
${cpugraph cpu1 30,120 FF8800 ff0000}${alignr}${cpugraph cpu2 30,120 FF8800 ff0000}${voffset -45}
${color1}CPU1: ${color3}${cpu cpu1}%${color} ${exec sensors|grep 'Core 0'|awk '{print $3}'} ${alignr 10}${color1}CPU2: ${color3}${cpu cpu2}%${color} ${exec sensors|grep 'Core 1'|awk '{print $3}'} ${voffset 25}
#############
# - DISKS - #
#############
${color3}DISK USAGE${color}
${font Open Sans Light:size=7,weight:normal}${color8}${fs_used_perc /home}% ${color2}/home${font}
${font Open Sans Light:size=7,weight:4normal}${color8}${fs_used_perc /}% ${color2}/${font}
################
# - RAM DATA - #
################
${color3}RAM USAGE${color}
${font Open Sans Light:size=7,weight:normal}${color2}RAM: ${color8}${memperc}%${font}
${font Open Sans Light:size=7,weight:normal}${color2}SWAP: ${color8}${swapperc}%${font}
#################
# - PROCESSES - #
#################
${voffset -117}
${goto 100}${color3}PROCESSES${color}
${goto 100}${color 00BFFF}${voffset -5}${font Ubuntu:size=7}${top name 1}${goto 180}${top cpu 1}${alignr 10}${top mem 1}%${font}
${goto 100}${color 00ACE6}${voffset -5}${font Ubuntu:size=7}${top name 2}${goto 180}${top cpu 2}${alignr 10}${top mem 2}%${font}
${goto 100}${color 0099CC}${voffset -5}${font Ubuntu:size=7}${top name 3}${goto 180}${top cpu 3}${alignr 10}${top mem 3}%${font}
${goto 100}${color 0085B2}${voffset -5}${font Ubuntu:size=7}${top name 4}${goto 180}${top cpu 4}${alignr 10}${top mem 4}%${font}
${goto 100}${color 007299}${voffset -5}${font Ubuntu:size=7}${top name 5}${goto 180}${top cpu 5}${alignr 10}${top mem 5}%${font}
${goto 100}${color 005F80}${voffset -5}${font Ubuntu:size=7}${top name 6}${goto 180}${top cpu 6}${alignr 10}${top mem 6}%${font}${color}${voffset 6} 
${color3}UPTIME: ${color8}${exec uptime | cut -f 1 -s --delimiter=','}${font}${color}
${color7}${hr}${color}${voffset -15} 
###############
# - NETWORK - #
###############
# WLAN0 Connection
${if_existing /proc/net/route wlan0}
${color1}Local IP:${color} ${color3}${addr wlan0}${color}
${execi 3600 curl -s "http://whatsmyip.net" -o ~/.cache/externalip.html -A "Mozilla/4.0"}${color1}External IP:${color} ${color3}${execi 3600 grep -o "IP Address is <input type="\" value="\">" ~/.cache/externalip.html | cut -f 6 -s --delimiter=" " | cut -f 2 -s --delimiter="\""}${color}
${upspeedgraph wlan0 50,120 5A2A1C FF6739 -t}${alignr}${downspeedgraph wlan0 50,120 7FC05E 3E5A32 -t}${voffset -65}
${color8}Up:${color} ${color3}${upspeed wlan0}${color}${alignr}${color8}Down:${color} ${color3}${downspeed wlan0}${color}
${color8}Sent:${color} ${color2}${totalup wlan0}${color}${alignr}${color8}Received:${color} ${color2}${totaldown wlan0}${color}
# ETH0 Connection
${else}${if_existing /proc/net/route eth0}
${color1}Local IP:${color} ${color3}${addr eth0}${color}
${execi 3600 curl -s "http://whatsmyip.net" -o ~/.cache/externalip.html -A "Mozilla/4.0"}${color1}External IP:${color} ${color3}${execi 3600 grep -o "IP Address is <input type="\" value="\">" ~/.cache/externalip.html | cut -f 6 -s --delimiter=" " | cut -f 2 -s --delimiter="\""}${color}
${upspeedgraph eth0 50,120 5A2A1C FF6739 -t}${alignr}${downspeedgraph eth0 50,120 7FC05E 3E5A32 -t}${voffset -65}
${color8}Up:${color} ${color3}${upspeed eth0}${color}${alignr}${color8}Down:${color} ${color3}${downspeed eth0}${color}
${color8}Sent:${color} ${color2}${totalup eth0}${color}${alignr}${color8}Received:${color} ${color2}${totaldown eth0}${color}
# ETH1 Connection
${else}${if_existing /proc/net/route eth1}
${color1}Local IP:${color} ${color3}${addr eth1}${color}
${execi 3600 curl -s "http://whatsmyip.net" -o ~/.cache/externalip.html -A "Mozilla/4.0"}${color1}External IP:${color} ${color3}${execi 3600 grep -o "IP Address is <input type="\" value="\">" ~/.cache/externalip.html | cut -f 6 -s --delimiter=" " | cut -f 2 -s --delimiter="\""}${color}
${upspeedgraph eth1 50,120 5A2A1C FF6739 -t}${alignr}${downspeedgraph eth1 50,120 7FC05E 3E5A32 -t}${voffset -65}
${color8}Up:${color} ${color3}${upspeed eth1}${color}${alignr}${color8}Down:${color} ${color3}${downspeed eth1}${color}
${color8}Sent:${color} ${color2}${totalup eth1}${color}${alignr}${color8}Received:${color} ${color2}${totaldown eth1}${color}
# ETH2 Connection
${else}${if_existing /proc/net/route eth2}
${color1}Local IP:${color} ${color3}${addr eth2}${color}
${execi 3600 curl -s "http://whatsmyip.net" -o ~/.cache/externalip.html -A "Mozilla/4.0"}${color1}External IP:${color} ${color3}${execi 3600 grep -o "IP Address is <input type="\" value="\">" ~/.cache/externalip.html | cut -f 6 -s --delimiter=" " | cut -f 2 -s --delimiter="\""}${color}
${upspeedgraph eth2 50,120 5A2A1C FF6739 -t}${alignr}${downspeedgraph eth2 50,120 7FC05E 3E5A32 -t}${voffset -65}
${color8}Up:${color} ${color3}${upspeed eth2}${color}${alignr}${color8}Down:${color} ${color3}${downspeed eth2}${color}
${color8}Sent:${color} ${color2}${totalup eth2}${color}${alignr}${color8}Received:${color} ${color2}${totaldown eth2}${color}
# PPP0 Connection
${else}${if_existing /proc/net/route ppp0}
${color1}Local IP:${color} ${color3}${addr ppp0}${color}
${execi 3600 curl -s "http://whatsmyip.net" -o ~/.cache/externalip.html -A "Mozilla/4.0"}${color1}External IP:${color} ${color3}${execi 3600 grep -o "IP Address is <input type="\" value="\">" ~/.cache/externalip.html | cut -f 6 -s --delimiter=" " | cut -f 2 -s --delimiter="\""}${color}
${upspeedgraph ppp0 50,120 5A2A1C FF6739 -t}${alignr}${downspeedgraph ppp0 50,120 7FC05E 3E5A32 -t}${voffset -65}
${color8}Up:${color} ${color3}${upspeed ppp0}${color}${alignr}${color8}Down:${color} ${color3}${downspeed ppp0}${color}
${color8}Sent:${color} ${color2}${totalup ppp0}${color}${alignr}${color8}Received:${color} ${color2}${totaldown ppp0}${color}
# NO Connection
${else}Network disconnected
${color6}Connect to a network to see statistics${color}
${endif}${endif}${endif}${endif}${endif}${voffset -25}

In case you want to make it show up at every start of your system one more small bash script is necessary. Copy and paste the following script in a text file and save it as “conky_start.sh”. Don’t forget to make this script executable.

#! /bin/bash
sleep 20
conky -c $HOME/.conky/.conkyrc
exit

The last necessary step is to copy all the script files we created in a folder named “.conky” under your home directory. To make “conky_start.sh” to run whenever your system starts depends on the Linux distribution you use. On Ubuntu Mate I use the “Preferences > Startup Applications” utility.

UPDATE (2013-11-26): Today I updated the script. Lately I realized that the findmyip.org website is down and doesn’t work any more, so I changed it and now the script uses the whatsmyip. Also I fixed the script to show the weather of today as big, and only the following two days. Previously, it was wrongly showing today twice and the last of the following four days.

#linux #script #conky #bash #system monitor
- 8 min read