Sujet : Re: Simple way for web to execute root shell script.
De : theom+news (at) *nospam* chiark.greenend.org.uk (Theo)
Groupes : comp.os.linux.misc comp.sys.raspberry-piDate : 24. May 2025, 08:27:12
Autres entêtes
Organisation : University of Cambridge, England
Message-ID : <8JE*00fdA@news.chiark.greenend.org.uk>
References : 1 2 3
User-Agent : tin/1.8.3-20070201 ("Scotasay") (UNIX) (Linux/5.10.0-28-amd64 (x86_64))
In comp.sys.raspberry-pi The Natural Philosopher <
tnp@invalid.invalid> wrote:
Sadly the data is not available in /sys or /proc AFAIK.
I wanted information on the temperature and data volumes on the SSDs and
the temperature of the ARM core. Plus data on the amount of data being
transported over the ethernet interface.
The tools that came to hand were vgcencmd, smartctl, df and ip. Plus
some sedery grepery and awkery
The script is (if you are interested)
#!/bin/bash
smartctl -a /dev/sda | grep Celsius | awk '{print $10}'
smartctl -a /dev/sdb | grep Celsius | awk '{print $10}'
vcgencmd measure_temp | sed -e 's/temp=//' | sed -e "s/'C//"
ip -s link show dev eth0 | awk 'FNR == 4 {print $1}'
ip -s link show dev eth0 | awk 'FNR == 6 {print $1}'
df -h | grep /dev/sd
[snip]
The intention is to poll that using AJAX and parse it into the position
of needles on dials in a web page.
Another option is to split this into two parts. The above is a script
that's run as root, which is set up by cron to run every minute (or
whatever). That outputs a file such as /var/www/whatever/stats.txt
Then Apache serves that file like any other file, no privileged access
needed.
Obviously in that case it's not live data, it can be up to a minute old.
But maybe that's not a problem, especially if you include a timestamp in the
data so the frontend knows when it's last updated. But for things like
temperatures maybe it's ok that you're lagging slightly behind as physical
constraints mean they don't change very fast.
Theo