LCDd extension: maxilcd
news2014-09-04-lcdd-extension-maxilcd

My LCDd extensions is a simple bash script and it integrates well with lcdproc. Nevertheless it displays things I missed in lcdproc:

  • ip-address
  • hostname
  • hard disk(s) temperatures
  • CPU utilization
  • CPU temperature (alias physical id 0)

Prerequirements #

  • Make sure, that LCDd is running. Your tools:

    vim /etc/lcdd.conf
    systemctl start lcdd
    systemctl status lcdd
    systemctl enable lcdd
    

    If you see a permission denied error, then a restart helps for an unknown reason.

  • (optional) Setup hddtemp and enable it's service. This will reduce the amount of temperature readings.

  • (optional) Make sure, that you have netcat installed. It is expected to have a binary, called nc somewhere in your path. Some distributions deliver ncat in which case a Symlink will do as well (or change the script)

The Program #

Copy the following bash script and remember its name:

#!/bin/bash
FIFO=/tmp/LCD
sleep 5

mkfifo $FIFO
nc localhost 13666 <> /tmp/LCD 1>/dev/null 2>/dev/null &
trap "kill $!; rm -f $FIFO; exit;" EXIT HUP INT TERM ABRT


cat <<EOF > $FIFO
hello
client_set name test
screen_add screen0
widget_add screen0 line1 string
widget_add screen0 line2 string
screen_add screen1
widget_add screen1 line1 string
widget_add screen1 line2 string
EOF

while [[ true ]]; do

  CPUstat=$(cat /proc/stat | grep 'cpu ' | awk '{printf "%.1f%",(($2+$4)*100/($2+$4+$5))}')
  CPUtemp=$(sensors | grep 'Physical id 0' | awk '{print $4}')
  HDDstat=$(ncat 127.0.0.1 7634 2>/dev/null | sed 's/|//m' | sed 's/||/ \n/g' | grep -v '*' | awk -F'|' '{printf "%s:%s ",$1,$3,$4}' | sed 's/\/dev\///g')

  # TODO: ncat works, nc or netcat does not, why?

  # logger $(ncat 127.0.0.1 7634)

cat <<EOF > $FIFO
widget_set screen0 line1 1 1 "CPU: $CPUtemp $CPUstat"
widget_set screen0 line2 1 2 "$HDDstat"
widget_set screen1 line1 1 1 "`hostname -i | cut -d' ' -f2`"
widget_set screen1 line2 1 2 "`hostname -f | cut -d' ' -f2`"
EOF

sleep 1
done

In this example I have copied the script to /usr/local/bin and if you had chosen an other path do not forget to change it in the following starter script as well. The following systemd.service must be copied to /etc/systemd/system/ and activated with systemctl start maxilcd.

/etc/systemd/system/maxilcd.service

[Unit]
Description=lcdservice
Requires=lcdd.service

[Service]
ExecStart=/bin/bash -c /usr/local/bin/maxilcd
Type=simple
User=nobody
Group=nobody

[Install]
WantedBy=multi-user.target

If that works enable it as well using

systemctl enable maxilcd
top