Re: How to persist text on the screen when the client exits?
Richard Neill <[email protected]> Tue, 01 Jan 2013 23:59:03 +0000
| Newsgroups | gmane.comp.sysutils.lcdproc |
|---|---|
| Message-ID | <[email protected]> |
Dear Eric, Thanks for your quick reply. I'm afraid that my simplified bash script may have added confusion - I do know about the -t option for the client. Also, I'd rather not respawn python every time - but in this case it's OK (the performance hit, while wasteful, is not actually an issue). The machine I'm monitoring is actually an ADSL router - it's job is just to run multilink ppp, and is rather overspecd, So, I'm attaching my script, which may make things a bit clearer. This is launched from cron with "@reboot". Anyway, it works fine, except that the screen is blank about half the time. What I really want is to treat the LCD display like a simple character device, into which I can echo text. I appreciate the sophistication of the lcdproc architecture, with support for buttons, menus etc, but in this particular use-case, I don't need it. Best wishes, Richard On 01/01/13 23:44, Eric Pooch wrote: > You need to re-imagine your client rather than the change the server. > Your client is spawning 4 processes every 2 seconds. This doesn't > seem like a good idea. > > As a temporary fix, the -t option for lcdproc_client.py will keep > the connection open for the time you specify. I would change your > final sleep command to account for this. > > --Eric > > On Jan 1, 2013, at 3:27 PM, Richard Neill wrote: > >> Dear All, >> >> I've just joined this list, so please excuse me if I ask an obvious >> question. >> >> I'm trying to get a server status monitor system working, >> monitoring a set of parameters of my choice (the lcdproc defaults >> aren't suitable for me here) >> >> So, I have LCDd running (with a 20x2 picolcd), and found the text >> client here: http://lcdproc-client.sourceforge.net/ >> >> I have a bash-script that sends strings to the client every few >> seconds, and they display on the LCD as expected. A simplified >> example: >> >> while : ; do hostname | lcdproc_client.py -f - sleep 1 date | >> lcdproc_client.py -f - sleep 1 done >> >> >> This displays the hostname and the date, alternately, as I expect. >> >> BUT, between these, every time the python script exits, the system >> keeps going back to either the LCDd default screen, or to blank >> (the value of ServerScreen). >> >> How can I get LCDd to just leave the text on screen as it was, >> until I explicitly overwrite it? >> >> Thanks very much, >> >> Richard >> >> >> P.S. Might I suggest that a "--text" option to lcdproc i.e. "write >> this line to screen, and exit" would be really useful in the >> default distribution. >> >> >> _______________________________________________ LCDproc mailing >> list [email protected] >> http://lists.omnipotent.net/mailman/listinfo/lcdproc > > _______________________________________________ LCDproc mailing list [email protected] http://lists.omnipotent.net/mailman/listinfo/lcdproc
lcd_status.sh
(application/x-shellscript, 2.9 KB)
#!/bin/bash
cd `dirname $0`
LCD_CLIENT="./lcdproc_client.py"
DEBUG=false
#20 x 2 lines. Prototype messages
#12345678901234567890
#12345678901234567890
#tub: 18:22:31
#up: 4 days
#cpu: 0.01 0.02 0.05
#disk: 13% used
#8.8.8.8 is alive
#bbc.co.uk is alive
#RUN/stop: SSH DHCPD
#BIND SMTP NTP APACHE
#pppd: call XXXXXX
#pppd: call XXXXXX
#ppp0: xx.xx.xx.xx
#eth0: 192.168.0.2
#20 char x 2 line. Too long and it gets truncated.
write_msg (){
MSG="$1"
[ "$DEBUG" == true ] && { echo "$MSG"; sleep 1 ;}
echo -ne "$MSG" | $LCD_CLIENT -f - -t 2 #returns after 2 seconds.
}
screen_1(){
#Hostname. Returns e.g.: "tub"
hostname=$(hostname -s)
#Time. Returns e.g.: "20:18:09"
time=$(date '+%H:%M:%S')
#Uptime. Returns e.g.: "up: 4 days"
uptime=$(uptime | cut -d , -f 1 | grep -oE 'up.*' | sed 's/up/up: /')
echo "$hostname: $time"$'\n'"$uptime"
}
screen_2(){
#Loadavg. Returns e.g.: "0.01 0.02 0.05"
loadavg=$(cat /proc/loadavg | cut -d ' ' -f 1-3)
#Disk used percent. Returns e.g.: "14%"
diskused=$(df -h | grep /dev/sda1 | grep -oE '..%')
echo "cpu: $loadavg"$'\n'"disk: $diskused used"
}
screen_3(){
#Services. Returns e.g.: "RUN/stop: SSH DHCPD\nBIND SMTP NTP APACHE" (where the service is captialised iff it is running.
#NB "service postfix status" won't run as non-root. So pgrep master instead.
services="RUN/stop: "
if service ssh status >/dev/null 2>&1; then services=$services"SSH "; else services=$services"ssh "; fi
if service isc-dhcp-server status >/dev/null 2>&1 ; then services=$services"DHCPD "; else services=$services"dhcpd "; fi
services=$services$'\n'
if service bind9 status >/dev/null 2>&1 ; then services=$services"BIND "; else services=$services"bind "; fi
if pgrep [m]aster >/dev/null 2>&1 ; then services=$services"SMTP "; else services=$services"smtp "; fi
if service ntp status >/dev/null 2>&1 ; then services=$services"NTP "; else services=$services"ntp "; fi
# if service xdm status >/dev/null 2>&1 ; then services=$services"XDM "; else services=$services"xdm "; fi
if service apache2 status >/dev/null 2>&1 ; then services=$services"APACHE "; else services=$services"apache "; fi
echo "$services"
}
screen_4(){
#Fping. Returns e.g.: "8.8.8.8 is alive\nbbc.co.uk is alive"
fping=$(fping 8.8.8.8 bbc.co.uk)
echo "$fping"
}
screen_5(){
#PPPD status. Returns the pppd processes and what they are calling. e.g.: "pppd: call xxxx\npppd: call xxxx"
pppd=$(ps aux | grep [p]ppd | grep -oE '[p]ppd.*' | sed 's/dsl-provider-//g' | sed -s 's/updetach//' | sed 's/ /: /')
echo "$pppd"
}
screen_6(){
#IP addresses. Returns e.g.: "ppp0: xx.xx.xx.xx\neth0: 192.168.0.2"
ips="ppp0: "$(ifconfig ppp0 | grep -oE 'inet addr:[0-9.]*' | cut -d : -f 2)$'\n'"eth0: "$(ifconfig eth0 | grep -oE 'inet addr:[0-9.]*' | cut -d : -f 2)$'\n'
echo "$ips"
}
while : ; do
write_msg "$(screen_1)"
write_msg "$(screen_2)"
write_msg "$(screen_3)"
write_msg "$(screen_4)"
write_msg "$(screen_5)"
write_msg "$(screen_6)"
done