Hello Octave,
Backticks can be fun. :-)
Since my "Desktop Environment" is basically gnu/screen and I do like to
keep an eye on the system's health, I wrote backticks that do pretty
much everything apart from making the coffee.
Since you indirectly raised the issue of contributing, you may want to
try to sell the idea of a "contrib" or "extras" directory in the screen
source tree, that might among other things include backticks for all
seasons.
Maybe s/o or other will flame you for "bloating" not the screen source
itself, but screen's source tree & packaging .. ;-)
But in our times where plugins everywhere, this might be the right
approach - and believe me, if I could readily have found samples of
backticks when I wrote mine, it would have saved me quite a bit of trial
and error.
I'm attaching some working backticks that may be of interest as well as
the relevant part of my ~/.screenrc.
For an idea of what it looks like, You can take a peek at:
http://www.geocities.com/fcky1000/fckz/diff.png
.. or some of the other screenshots in the same ../fckz directory.
Cheers,
CJ
#!/bin/sh
#-------------------------------------------------------------------------------
# ~/bin/weather : grab current temperature from local weather station
#
# usage : normally used as a GNU/screen backtick
#
# notes : 1. Fiddle awk variables or add converter for Celsius only
# : 2. Change STATION's KISP to whatever for your local station
# : 3. Delay between updates is 20 minutes by default
#-------------------------------------------------------------------------------
station='http://weather.noaa.gov/weather/current/KISP.html'
delay=1200
cpink="\033p\033[38;5;162m"
cdflt="\033[0m\033"
temp=$(curl -s $station | grep 'F (' | head -n 1 | awk '{print $3}')
echo -e $cpink $temp $cdflt
exit 0
#!/usr/bin/gawk -f
#-------------------------------------------------------------------------------
# ~/bin/cpustat : display cpu utilization
#
# usage : normally used as a GNU/screen backtick
#
# notes : 1. Works on the assumption that /proc/stat's first line
# : has the total "jiffies" since boot up used by the
# : different types of tasks in the system. See the
# : filesystems/proc.txt document in kernel source tree
# :
# : 2. Displays a total CPU% (user+system+nice) as well as
# : user CPU% system CPU% and nice CPU%
#-------------------------------------------------------------------------------
BEGIN {
file = "/proc/stat"
while (getline < file) { # read first line
# extract jiffies:
user=$2-user_saved; # . user
nice=$3-nice_saved; # . nice user
syst=$4-syst_saved; # . system
idle=$5-idle_saved; # . idle
wait=$6-wait_saved; # . iowait
irqs=$7-irqs_saved; # . irq
sirq=$8-sirq_saved; # . softirq
cact=user+syst+nice; # what counts
ctot=user+nice+syst+idle+wait+irqs+sirq; # total activity
tcpu=cact/ctot*100; # total % cpu utilization
ucpu=user/ctot*100; # user % cpu utilization
scpu=syst/ctot*100; # system % cpu utilization
ncpu=nice/ctot*100; # nice % cpu utilization
printf "%3.1f%% %3.1f%% %3.1f%% %3.1f%%\n",tcpu,ucpu,scpu,ncpu
user_saved=$2; # save the current jiffies
nice_saved=$3; # values for the next loop
syst_saved=$4;
idle_saved=$5;
wait_saved=$6;
irqs_saved=$7;
sirq_saved=$8;
close(file) # re-read file
system("sleep 3")
}
}
#!/usr/bin/gawk -f
#-----------------------------------------------------------------------------
# ~/bin/memswap : display percentage of ram & sawp currently in use
#
# usage : normally used as a GNU/screen backtick
#
# notes : 1. % ram used = ((total ram - used) / total ram) * 100
# : 2. % swap used = ((total swap - used) / total swap) * 100
#-----------------------------------------------------------------------------
BEGIN {
while (getline < "/proc/meminfo") {
if ($1=="MemTotal:") {mt = $2}; # mt = total ram on system
if ($1=="MemFree:") {mf = $2}; # mf = free ram
if ($1=="Buffers:") {mb = $2}; # mb = ram used for buffers
if ($1=="Cached:") {mc = $2}; # mc = ram used for cache
if ($1=="SwapTotal:") {st = $2}; # st = total swap
if ($1=="SwapFree:") {sf = $2}; # sf = free swap
}
exit;
}
END {
pmu = (mt-(mf+mb+mc)) * 100 / mt; # pmu = % of ram used
psu = ((st-sf) * 100 / st); # psu = % of swap used
printf ("%2.1f%s %2.1f%s\n"), pmu,"%", psu,"%";
}
#!/bin/sh
#-------------------------------------------------------------------------------
# ~/bin/ntstat : display eth0 up/down activity in kilobytes
#
# usage : normally used as a GNU/screen backtick
#
# notes : 1. default delay is one second - adjust $delay variable
# : 2. netstat gives TX/RX counts -> awk prints the delta
# : 3. the script exits if the write fails so that the script
# : ends when screen terminates
#-------------------------------------------------------------------------------
interface=eth0
delay=1
get_data()
{
netstat -ni | awk '/^'"$interface"'/{print$4,$8}'
}
init_data()
{
netdata=$(get_data)
prevrxcnt=$(echo $netdata | awk '{print$1}')
prevtxcnt=$(echo $netdata | awk '{print$2}')
}
save_data()
{
netdata=$(get_data)
rxcnt=$(echo $netdata | awk '{print$1}')
txcnt=$(echo $netdata | awk '{print$2}')
diffrxcnt=$(($rxcnt - $prevrxcnt))
difftxcnt=$(($txcnt - $prevtxcnt))
prevrxcnt=$rxcnt
prevtxcnt=$txcnt
}
init_data
while sleep $delay;
do
save_data
echo $diffrxcnt $difftxcnt | # pipe data to an awk print
awk '{printf "%4.1fk/s %4.1fk/s\n",$1*576/1024,$2*567/1024}' || exit 1
done
exit 0
#!/bin/bash
#-------------------------------------------------------------------------------
# ~/bin/systemp : display current system temperature as reported by acpi
#
# usage : normally used as a GNU/screen backtick
#
# notes :
#-------------------------------------------------------------------------------
awk '{ printf "%sC", $2 }' /proc/acpi/thermal_zone/THRM/temperature
#!/bin/sh
#-------------------------------------------------------------------------------
# ~/bin/weather : grab current temperature from local weather station
#
# usage : normally used as a GNU/screen backtick
#
# notes : 1. Fiddle awk variables or add converter for Celsius only
# : 2. Change STATION's KISP to whatever for your local station
# : 3. Delay between updates is 20 minutes by default
#-------------------------------------------------------------------------------
station='http://weather.noaa.gov/weather/current/KISP.html'
delay=1200
while :
do
curl -s $station | grep 'F (' | head -n 1 | awk '{print $3 $4}' || exit 1
sleep $delay
done
exit 0
#===================================================================================================
# Hardstatus line - temperature, cpu, ram, swap, network, loadavg + session &
date/time & weather
#===================================================================================================
backtick 0 60 60 /home/gavron/bin/bt-systemp # system temperature
backtick 1 0 0 /home/gavron/bin/bt-cpustat # cpu utilization
backtick 2 60 60 /home/gavron/bin/bt-memswap # ram & swap utilization
backtick 3 0 0 /home/gavron/bin/bt-netstat # eth0 up/down traffic in Kbytes
backtick 4 0 0 /home/gavron/bin/bt-weather # local outside temperature
caption always "%{+d wk} " # naughty hack! - adds
separator .. wastes one line
#hardstatus alwayslastline "%{+r wk}%H%{+b wk} | %0` | %1` | %2` | %3` %{+b
wk}| %{+b wk}%l%{+b wk} |%{+b mk} %n %t %{+b wk}| %{+b wk}%W %=|%{+b wk} %4` |
%D %m/%d/%y %c:%s"
hardstatus alwayslastline "%{+b kw}%H%{+b kw} | %0` | %1` | %2` | %3` | %l
|%{-b km} %n %t %{+b kw}| %W %=| %4` | %D %m/%d/%y %c:%s"