Network Traffic, Battery, Clock and Mocp in Status Bar (Bash version)

All in one
(working on awesome 2.2)

This is a homemade script to populate Mocp, Batt, Network, Load and Clock, from a bash script.

Awesome configuration
textbox zik {   width = 200 text = 'Pas de musique' bg = "#444444" fg = "#cccccc" mouse {       button = "1" command = "spawn" arg = "exec mocp -G" }   mouse {       button = "3" command = "spawn" arg = "exec mocp -f" } } progressbar batt {   height = 1 width = 40 bar {       bordercolor = "#CCCCCC" fg = "#6666FF" } } graph ifeth0 {   height = 1 bordercolor = "#CCCCCC" width = 40 padding_left = 2 data {       scale = true max = 1 fg = "#00FF00" }   data {       style = line scale = true max = 1 fg = "#0000FF" } } graph cpu {   height = 1 bordercolor = "#CCCCCC" width = 40 padding_left = 2 data {       style = line scale = true max = 200 fg = "#FF0000" }   data {       style = line scale = true max = 200 fg = "#ffb400" } } textbox clock {   width = 100 text_align = center text = " " } iconbox logout {   image = "/usr/share/icons/gnome/16x16/actions/gnome-session-logout.png" resize = true mouse {       button = "1" command = "spawn" arg = "exec gnome-session-save --kill --gui" } }

Bash script
Make sure to adapt it before execute ! Copy it to your ~/bin/awesome-wid


 * 1) !/bin/bash

CACHE=~/.awesome-wid MOCP_CACHE=~/.mocp-cache

while true; do

. $CACHE
 * 1) Read cache

echo 0 widget_tell clock `date '+%d/%m %H:%M:%S'` | awesome-client
 * 1) Clock

CPU0=`grep cpu0 /proc/stat | awk '{print $2"+"$3"+"$4}'` CPU0=$(($CPU0)) CPU0_D=$(($CPU0-$OLD_CPU0)) CPU1=`grep cpu1 /proc/stat | awk '{print $2"+"$3"+"$4}'` CPU1=$(($CPU1)) CPU1_D=$(($CPU1-$OLD_CPU1))
 * 1) CPU

echo 0 widget_tell cpu $CPU0_D,$CPU1_D | awesome-client

mocp -i > $MOCP_CACHE MOCP_TITLE=`cat $MOCP_CACHE | grep -e '^SongTitle:' | sed -r 's/^.*: //'` if [ "X$MOCP_TITLE" != "X" ] ; then MOCP_ARTIST=`cat $MOCP_CACHE | grep -e '^Artist:' | awk '{print $2}'` MOCP_TITLE=`cat $MOCP_CACHE | grep -e '^SongTitle:' | sed -r 's/^.*: //'` MOCP_ALL=`cat $MOCP_CACHE | grep -e '^TotalSec:' | awk '{print $2}'` MOCP_CUR=`cat $MOCP_CACHE | grep -e '^CurrentSec:' | awk '{print $2}'` MOCP_PER=$(($MOCP_CUR * 100 / $MOCP_ALL)) echo 0 widget_tell zik [$MOCP_PER%\] $MOCP_ARTIST - $MOCP_TITLE | awesome-client else echo 0 widget_tell zik Pas de musique | awesome-client fi
 * 1) Mocp

ETH0_IN=`grep eth0 /proc/net/dev | sed 's/:/\ /' | awk '{print $2}'` ETH0_OUT=`grep eth0 /proc/net/dev | sed 's/:/\ /' | awk '{print $10}'`
 * 1) Interface eth0

ETH0_IN_D=$(($ETH0_IN-$OLD_ETH0_IN)) ETH0_OUT_D=$(($ETH0_OUT-$OLD_ETH0_OUT))

echo 0 widget_tell ifeth0 $ETH0_IN_D,$ETH0_OUT_D | awesome-client

BATT_ALL=`grep "last full capacity:" /proc/acpi/battery/BAT0/info | awk '{print $4}'` BATT_CUR=`grep "remaining capacity:" /proc/acpi/battery/BAT0/state | awk '{print $3}'` BATT_PER=$(($BATT_CUR * 100 / $BATT_ALL)) echo 0 widget_tell batt $BATT_PER | awesome-client
 * 1) Batterie

echo "OLD_CPU0=$CPU0" > $CACHE echo "OLD_CPU1=$CPU1" >> $CACHE echo "OLD_ETH0_IN=$ETH0_IN" >> $CACHE echo "OLD_ETH0_OUT=$ETH0_OUT" >> $CACHE
 * 1) Write cache

sleep 1
 * 1) Sleep 1

done;

Initial cache file
Copy it to ~/.awesome-wid

OLD_CPU0=0 OLD_CPU1=0 OLD_ETH0_IN=0 OLD_ETH0_OUT=0