rendered paste body#!/bin/awk -fBEGIN { while (system("pgrep awesome")) # make sure awesome-wm has started { print "waiting for 'awsome-wm' to start"; system("sleep 2"); } date_cmd = "LANG=de_CH date +\"%X %A, %e %b\""; #socket = "/home/calmar/.awesome_ctl.0" # |& permission denied osum = 0; oidle = 0;}{ while (!system("sleep 1")) # still hard to ctrl-c, but well.. { ################################################## # date -> date_str date_cmd | getline date_str; close(date_cmd); ################################################## # cpu -> full_cpu xxx: may check once what it actually does... ocpustats = 0; while ((getline < "/proc/stat") > 0) { close("/proc/stat"); # xxx: scanning only the first line/cpu for now break; } nsum = 0; for (i = 2; i <= NF; i++) # add together all values nsum += $i; idlediff = $5 - oidle; # new idle - old idle frmtotal = nsum - osum - (idlediff < 0 ? idlediff : 0); # idlediff can be < 0 ? frmtotal = frmtotal < 1 ? 1 : frmtotal; full_cpu = 100 - (idlediff > 0 ? idlediff : 0) * 100 / frmtotal; osum = nsum; oidle = $5; ################################################## # mem count = 0; while ((getline < "/proc/meminfo") > 0) { if ("MemFree:" == $1) # xxx: better use a 'case' maybe { mem_free = $2; count++; } else if ("MemTotal:" == $1) { mem_total = $2; count++; } else if ("SwapFree:" == $1) { swap_free = $2; count++; } else if ("SwapTotal:" == $1) { swap_total = $2; count++; } if (count >= 4) { break; # all info is there } } close("/proc/meminfo"); mem_full = 100 * (mem_total - mem_free) / mem_total; swap_full = 100 * (swap_total - swap_free)/ swap_total; ################################################## # ethernet ################################################## # print the collected infos print "0 widget_tell pb_mem " mem_full; print "0 widget_tell pb_swap " swap_full; print "0 widget_tell pb_cpu " full_cpu; print "0 widget_tell tb_date_time " date_str; } }