• Simple way for web to execute root shell script.

    From The Natural Philosopher@21:1/5 to All on Fri May 23 13:26:34 2025
    XPost: comp.sys.raspberry-pi

    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?


    --
    "Anyone who believes that the laws of physics are mere social
    conventions is invited to try transgressing those conventions from the
    windows of my apartment. (I live on the twenty-first floor.) "

    Alan Sokal

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Pancho@21:1/5 to The Natural Philosopher on Fri May 23 13:51:57 2025
    XPost: comp.sys.raspberry-pi

    On 5/23/25 13:26, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

     Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?



    Dunno, change script ownership to root and use setuid, sudo chmod u+s.
    It used to work, nowadays who knows? It did used to provide security holes.

    <https://askubuntu.com/questions/1391359/how-to-let-a-non-privelegde-user-run-a-program-requiring-root-permsiossions-wit>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John-Paul Stewart@21:1/5 to The Natural Philosopher on Fri May 23 10:14:42 2025
    XPost: comp.sys.raspberry-pi

    On 2025-05-23 8:26 a.m., The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

     Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    Use sudo to call the script. First, drop a file into /etc/sudoers.d/ containing something like the following (untested):

    www ALL = (root) NOPASSWD: /path/to/script

    That should allow Apache running as www to call 'sudo /path/script' to
    run 'script' as root with no password needed. But at the same time, the
    www user won't be able to run anything else as root (nor any other user).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to The Natural Philosopher on Fri May 23 14:08:25 2025
    XPost: comp.sys.raspberry-pi

    On Fri, 23 May 2025 13:26:34 +0100, The Natural Philosopher wrote:

    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    As you probably already know, the system won't run shell scripts as setuid, even if the setuid bit is set. So, the direct route is out.


    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    My gut reaction would be to have the webserver use sudo(1) (with suitable limitations set in the /etc/sudoers file) to run the script via a system(3) call.

    If you mistrust sudo(1), then you /could/ write a simple setuid wrapper program that executes the script after making some rudimentary userid checks
    (ruid == www, euid == root, etc. (perhaps check that session leader is apache?))


    HTH
    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Lew Pitcher on Fri May 23 14:23:11 2025
    XPost: comp.sys.raspberry-pi

    On Fri, 23 May 2025 14:08:25 +0000, Lew Pitcher wrote:
    [snip]

    If you mistrust sudo(1), then you /could/ write a simple setuid wrapper program
    that executes the script after making some rudimentary userid checks
    (ruid == www, euid == root, etc. (perhaps check that session leader is apache?))

    Nope, not session leader.
    But process group leader works.

    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Pancho on Fri May 23 14:47:35 2025
    XPost: comp.sys.raspberry-pi

    On Fri, 23 May 2025 13:51:57 +0100, Pancho wrote:

    On 5/23/25 13:26, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

     Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?



    Dunno, change script ownership to root and use setuid, sudo chmod u+s.
    It used to work, nowadays who knows? It did used to provide security holes.

    FWIW, the Linux kernel does not honour the setuid bit when running hashbang scripts.

    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Pancho on Fri May 23 16:00:48 2025
    XPost: comp.sys.raspberry-pi

    On 23/05/2025 13:51, Pancho wrote:
    On 5/23/25 13:26, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

      Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?



    Dunno, change script ownership to root and use setuid, sudo chmod u+s.
    It used to work, nowadays who knows? It did used to provide security holes.

    doesnt seem to anymore

    <https://askubuntu.com/questions/1391359/how-to-let-a-non-privelegde-user-run-a-program-requiring-root-permsiossions-wit>

    --
    How fortunate for governments that the people they administer don't think.

    Adolf Hitler

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Lew Pitcher on Fri May 23 16:02:46 2025
    XPost: comp.sys.raspberry-pi

    On 23/05/2025 15:08, Lew Pitcher wrote:
    On Fri, 23 May 2025 13:26:34 +0100, The Natural Philosopher wrote:

    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    As you probably already know, the system won't run shell scripts as setuid, even if the setuid bit is set. So, the direct route is out.


    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    My gut reaction would be to have the webserver use sudo(1) (with suitable limitations set in the /etc/sudoers file) to run the script via a system(3) call.

    cant one execute it direct from apache?
    This is how I was thinking of doing it



    If you mistrust sudo(1), then you /could/ write a simple setuid wrapper program
    that executes the script after making some rudimentary userid checks
    (ruid == www, euid == root, etc. (perhaps check that session leader is apache?))

    Thats how I have done it in the past.

    HTH

    --
    How fortunate for governments that the people they administer don't think.

    Adolf Hitler

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Lew Pitcher on Fri May 23 16:03:13 2025
    XPost: comp.sys.raspberry-pi

    On 23/05/2025 15:23, Lew Pitcher wrote:
    On Fri, 23 May 2025 14:08:25 +0000, Lew Pitcher wrote:
    [snip]

    If you mistrust sudo(1), then you /could/ write a simple setuid wrapper program
    that executes the script after making some rudimentary userid checks
    (ruid == www, euid == root, etc. (perhaps check that session leader is apache?))

    Nope, not session leader.
    But process group leader works.

    Useful info. Thx


    --
    “when things get difficult you just have to lie”

    ― Jean Claud Jüncker

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to John-Paul Stewart on Fri May 23 16:05:22 2025
    XPost: comp.sys.raspberry-pi

    On 23/05/2025 15:14, John-Paul Stewart wrote:
    On 2025-05-23 8:26 a.m., The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

     Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    Use sudo to call the script. First, drop a file into /etc/sudoers.d/ containing something like the following (untested):

    www ALL = (root) NOPASSWD: /path/to/script

    That should allow Apache running as www to call 'sudo /path/script' to
    run 'script' as root with no password needed. But at the same time, the
    www user won't be able to run anything else as root (nor any other user).

    That is actually perfectly fine. I like that it nails everything down to
    one perfectly useless script to hacker.

    Now to solve the nightmare of apache site config to allow it to execute
    that directly...



    --
    “when things get difficult you just have to lie”

    ― Jean Claud Jüncker

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Lew Pitcher on Fri May 23 16:06:15 2025
    XPost: comp.sys.raspberry-pi

    On 23/05/2025 15:47, Lew Pitcher wrote:
    On Fri, 23 May 2025 13:51:57 +0100, Pancho wrote:

    On 5/23/25 13:26, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

     Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?



    Dunno, change script ownership to root and use setuid, sudo chmod u+s.
    It used to work, nowadays who knows? It did used to provide security holes.

    FWIW, the Linux kernel does not honour the setuid bit when running hashbang scripts.

    So I discovered...and that is fair enough, as its a *bit* of security hole


    --
    “when things get difficult you just have to lie”

    ― Jean Claud Jüncker

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Haber@21:1/5 to The Natural Philosopher on Fri May 23 17:24:23 2025
    XPost: comp.sys.raspberry-pi

    The Natural Philosopher <tnp@invalid.invalid> wrote:
    On 23/05/2025 15:08, Lew Pitcher wrote:
    On Fri, 23 May 2025 13:26:34 +0100, The Natural Philosopher wrote:

    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    As you probably already know, the system won't run shell scripts as setuid, >> even if the setuid bit is set. So, the direct route is out.


    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    My gut reaction would be to have the webserver use sudo(1) (with suitable
    limitations set in the /etc/sudoers file) to run the script via a system(3) >> call.

    cant one execute it direct from apache?

    If it's a shell script then it won't run as root even if it is suid
    root.

    I'd go the sudo way, but I'm not neutral about that¹.

    Greetings
    Marc

    ¹ I maintain sudo in Debian
    --
    ---------------------------------------------------------------------------- Marc Haber | " Questions are the | Mailadresse im Header Rhein-Neckar, DE | Beginning of Wisdom " |
    Nordisch by Nature | Lt. Worf, TNG "Rightful Heir" | Fon: *49 6224 1600402

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Marc Haber on Fri May 23 17:53:21 2025
    XPost: comp.sys.raspberry-pi

    On 23/05/2025 16:24, Marc Haber wrote:
    The Natural Philosopher <tnp@invalid.invalid> wrote:
    On 23/05/2025 15:08, Lew Pitcher wrote:
    On Fri, 23 May 2025 13:26:34 +0100, The Natural Philosopher wrote:

    I have a shell script that monitors hardware stuff - it needs to run as >>>> root and be called by Apache as user www.

    As you probably already know, the system won't run shell scripts as setuid, >>> even if the setuid bit is set. So, the direct route is out.


    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    My gut reaction would be to have the webserver use sudo(1) (with suitable >>> limitations set in the /etc/sudoers file) to run the script via a system(3) >>> call.

    cant one execute it direct from apache?

    If it's a shell script then it won't run as root even if it is suid
    root.

    I'd go the sudo way, but I'm not neutral about that¹.

    I did in fact go that way...
    After stumbling through the usual mess of 'it worked perfectly well
    before so let's change the way we do it' crap with apache2 versus 2.4..


    Greetings
    Marc

    ¹ I maintain sudo in Debian

    --
    “Puritanism: The haunting fear that someone, somewhere, may be happy.”

    H.L. Mencken, A Mencken Chrestomathy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eli the Bearded@21:1/5 to tnp@invalid.invalid on Fri May 23 16:46:10 2025
    XPost: comp.sys.raspberry-pi

    In comp.os.linux.misc, The Natural Philosopher <tnp@invalid.invalid> wrote:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    My "quickest and simplest solution":

    $ su
    Password:
    # sed -i -e 's,^www:.*,www:x:0:0:Apache:/var/www:/usr/sbin/nologin,' /etc/passwd
    # apachectl restart
    # ^D
    $

    YMMV.

    Elijah
    ------
    personally would run the script from cron and have Apache view results

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to The Natural Philosopher on Fri May 23 18:44:28 2025
    XPost: comp.sys.raspberry-pi

    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid> wrote:
    I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    You've been given lots of options already. But not this one.

    What "hardware stuff" is it monitoring? If it is reading files in
    /proc and/or /sys to obtain its "data" then another alternative would
    be to setup /proc and /sys to be mounted group or world readable (or to
    reset permissions on the necessary files via a rc.local boot script to
    group or world readable). That would let the script "monitor" without
    being root. Then you could even convert the script into a CGI script
    (which Apache is more than able to execute, and doing so for minimal
    text output involves the script outputting a handful of HTTP headers
    before the monitor data) and get your "monitoring data" back via
    Apache.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Rich on Fri May 23 21:44:51 2025
    XPost: comp.sys.raspberry-pi

    On 23/05/2025 19:44, Rich wrote:
    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid> wrote:
    I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    You've been given lots of options already. But not this one.

    What "hardware stuff" is it monitoring? If it is reading files in
    /proc and/or /sys to obtain its "data" then another alternative would
    be to setup /proc and /sys to be mounted group or world readable (or to
    reset permissions on the necessary files via a rc.local boot script to
    group or world readable). That would let the script "monitor" without
    being root. Then you could even convert the script into a CGI script
    (which Apache is more than able to execute, and doing so for minimal
    text output involves the script outputting a handful of HTTP headers
    before the monitor data) and get your "monitoring data" back via
    Apache.

    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

    A typical output is

    40
    44
    57.4
    220513467
    17430583
    /dev/sda2 110G 6.1G 98G 6% /
    /dev/sda1 510M 66M 445M 13% /boot/firmware
    /dev/sda3 366G 126G 222G 37% /home
    /dev/sdb1 219G 130G 78G 63% /backup
    /dev/sdb2 1.6T 1.3T 297G 81% /home/Media
    /dev/sda5 990G 559G 381G 60% /home/Media/Unedited
    /dev/sda6 366G 26G 322G 8% /backup2


    The intention is to poll that using AJAX and parse it into the position
    of needles on dials in a web page.

    I used to do this via SNMP, but less and less is available with SNMP and
    its clunky as shit,

    If any of that is in /proc or /sys. I would like to hear about it.

    None of this is precision stuff: I am building an ARM based NAS and I
    just need a quick and easy way to keep an eye on it to see if it gets to
    hot or too full as I develop stuff




    --
    In theory, there is no difference between theory and practice.
    In practice, there is.
    -- Yogi Berra

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From druck@21:1/5 to The Natural Philosopher on Fri May 23 22:17:22 2025
    XPost: comp.sys.raspberry-pi

    On 23/05/2025 13:26, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    It probably doesn't need to run as root, but rather the www (I suspect
    you mean www-data) user should be in the correct group to access the
    hardware.

    I have various Pi's running Python flask http servers or use the nginx
    web server and uwsgi to run Python programs. They all run as the
    www-data user, and the have access to cameras, i2c and 1-wire
    temperature sensors (groups video, i2c and gpio), and also the disk
    group so they can write results to sqlite databases. Nothing runs as root.

    ---druck

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to The Natural Philosopher on Fri May 23 23:11:39 2025
    XPost: comp.sys.raspberry-pi

    On Fri, 23 May 2025 13:26:34 +0100, The Natural Philosopher wrote:

    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    You could have it running all the time and accepting requests to do things
    via a socket interface that you can connect to from a web-based frontend.

    Alternatively, it can be running its own mini HTTP server, either directly exposed on a public port or accessed via a server-side proxy (what they
    insist on calling a “reverse proxy”) from Apache/Nginx.

    Either way, this would likely be awkward to implement as a shell script. I would recommend using Python instead.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Marc Haber on Sat May 24 00:37:16 2025
    XPost: comp.sys.raspberry-pi

    On Fri, 23 May 2025 17:24:23 +0200, Marc Haber wrote:

    ¹ I maintain sudo in Debian

    For better or for worse? ;)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to The Natural Philosopher on Sat May 24 02:13:59 2025
    XPost: comp.sys.raspberry-pi

    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid> wrote:
    On 23/05/2025 19:44, Rich wrote:
    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid> wrote: >>> I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    You've been given lots of options already. But not this one.

    What "hardware stuff" is it monitoring? If it is reading files in
    /proc and/or /sys to obtain its "data" then another alternative would
    be to setup /proc and /sys to be mounted group or world readable (or to
    reset permissions on the necessary files via a rc.local boot script to
    group or world readable). That would let the script "monitor" without
    being root. Then you could even convert the script into a CGI script
    (which Apache is more than able to execute, and doing so for minimal
    text output involves the script outputting a handful of HTTP headers
    before the monitor data) and get your "monitoring data" back via
    Apache.

    Sadly the data is not available in /sys or /proc AFAIK.

    Yeah, at least the smart data is not (as far as I am aware) available
    via /proc or /sys.

    Another option. You could setup a cronjob, as root, to run your script
    on some periodic basis (once per minute, every 10 minutes, etc.) and
    save the results into a file that is readable via the 'www' user (or to
    save the info directly into a file in the Apache htdocs hierarchy from
    where you want to retreive it).

    Then you can 'pull' the data via Apache from that file.

    You'd have data that is up to date as of the last run of the script,
    but you would not have the "exactly now it is Y" aspect (unless your
    AJAX pulled just after a cronjob run *and* you were watching the
    'meters' at that very moment).

    You could even include a "date" as the first line, so you could see if something got hung by the time value being too far in the past.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From c186282@21:1/5 to The Natural Philosopher on Sat May 24 01:43:53 2025
    XPost: comp.sys.raspberry-pi

    On 5/23/25 8:26 AM, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

     Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?


    Ummm ... just sayin' ... do you REALLY want/need that ???

    Seems like a recipe for sure disaster.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Theo@21:1/5 to The Natural Philosopher on Sat May 24 08:27:12 2025
    XPost: comp.sys.raspberry-pi

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to All on Sat May 24 09:20:15 2025
    XPost: comp.sys.raspberry-pi

    On 24/05/2025 06:43, c186282 wrote:
    On 5/23/25 8:26 AM, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

      Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?


      Ummm ... just sayin' ... do you REALLY want/need that ???

      Seems like a recipe for sure disaster.

    Why on earth would you say that?

    If I told you that you didnt need an engine start switch inside your car because it was a security hazard, you would be puzzled, too,.

    --
    The biggest threat to humanity comes from socialism, which has utterly
    diverted our attention away from what really matters to our existential survival, to indulging in navel gazing and faux moral investigations
    into what the world ought to be, whilst we fail utterly to deal with
    what it actually is.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Rich on Sat May 24 09:18:31 2025
    XPost: comp.sys.raspberry-pi

    On 24/05/2025 03:13, Rich wrote:
    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid> wrote:
    On 23/05/2025 19:44, Rich wrote:
    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid> wrote: >>>> I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    You've been given lots of options already. But not this one.

    What "hardware stuff" is it monitoring? If it is reading files in
    /proc and/or /sys to obtain its "data" then another alternative would
    be to setup /proc and /sys to be mounted group or world readable (or to
    reset permissions on the necessary files via a rc.local boot script to
    group or world readable). That would let the script "monitor" without
    being root. Then you could even convert the script into a CGI script
    (which Apache is more than able to execute, and doing so for minimal
    text output involves the script outputting a handful of HTTP headers
    before the monitor data) and get your "monitoring data" back via
    Apache.

    Sadly the data is not available in /sys or /proc AFAIK.

    Yeah, at least the smart data is not (as far as I am aware) available
    via /proc or /sys.

    No. I didnt think so either. :-(

    Neither I think is the vcgencmd stuff.
    Probably disk and network data is in there somewhere.



    Another option. You could setup a cronjob, as root, to run your script
    on some periodic basis (once per minute, every 10 minutes, etc.) and
    save the results into a file that is readable via the 'www' user (or to
    save the info directly into a file in the Apache htdocs hierarchy from
    where you want to retreive it).

    Then you can 'pull' the data via Apache from that file.

    I've used that approach elsewhere, But it means more storage.

    You'd have data that is up to date as of the last run of the script,
    but you would not have the "exactly now it is Y" aspect (unless your
    AJAX pulled just after a cronjob run *and* you were watching the
    'meters' at that very moment).

    You could even include a "date" as the first line, so you could see if something got hung by the time value being too far in the past.

    Could do, yes. But this way I get up to the second data.

    Essentially this is pushing the Pi 4 a bit to its limits and I want to
    be able to do a snap inspection.


    --
    "Fanaticism consists in redoubling your effort when you have
    forgotten your aim."

    George Santayana

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to The Natural Philosopher on Sat May 24 10:58:27 2025
    XPost: comp.sys.raspberry-pi

    The Natural Philosopher <tnp@invalid.invalid> writes:
    On 24/05/2025 06:43, c186282 wrote:
    On 5/23/25 8:26 AM, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to
    run as root and be called by Apache as user www.

      Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?
      Ummm ... just sayin' ... do you REALLY want/need that ???
      Seems like a recipe for sure disaster.

    Why on earth would you say that?

    Standard Usenet style when you don’t know how to solve someone’s problem (or didn’t understand it) is to argue with their requirements instead.

    --
    https://www.greenend.org.uk/rjk/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Richard Kettlewell on Sat May 24 11:27:52 2025
    XPost: comp.sys.raspberry-pi

    On 24/05/2025 10:58, Richard Kettlewell wrote:
    The Natural Philosopher <tnp@invalid.invalid> writes:
    On 24/05/2025 06:43, c186282 wrote:
    On 5/23/25 8:26 AM, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to
    run as root and be called by Apache as user www.

      Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?
      Ummm ... just sayin' ... do you REALLY want/need that ???
      Seems like a recipe for sure disaster.

    Why on earth would you say that?

    Standard Usenet style when you don’t know how to solve someone’s problem (or didn’t understand it) is to argue with their requirements instead.

    Bit wry for you Richard ;-)

    --
    Truth welcomes investigation because truth knows investigation will lead
    to converts. It is deception that uses all the other techniques.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Elvidge@21:1/5 to The Natural Philosopher on Sat May 24 13:28:35 2025
    XPost: comp.sys.raspberry-pi

    On 23/05/2025 at 21:44, The Natural Philosopher wrote:
    On 23/05/2025 19:44, Rich wrote:
    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid>
    wrote:
    I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    You've been given lots of options already. But not this one.

    What "hardware stuff" is it monitoring? If it is reading files in
    /proc and/or /sys to obtain its "data" then another alternative would
    be to setup /proc and /sys to be mounted group or world readable (or to
    reset permissions on the necessary files via a rc.local boot script to
    group or world readable). That would let the script "monitor" without
    being root. Then you could even convert the script into a CGI script
    (which Apache is more than able to execute, and doing so for minimal
    text output involves the script outputting a handful of HTTP headers
    before the monitor data) and get your "monitoring data" back via
    Apache.

    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

    A typical output is

    40
    44
    57.4
    220513467
    17430583
    /dev/sda2 110G 6.1G 98G 6% /
    /dev/sda1 510M 66M 445M 13% /boot/firmware
    /dev/sda3 366G 126G 222G 37% /home
    /dev/sdb1 219G 130G 78G 63% /backup
    /dev/sdb2 1.6T 1.3T 297G 81% /home/Media
    /dev/sda5 990G 559G 381G 60% /home/Media/Unedited
    /dev/sda6 366G 26G 322G 8% /backup2


    The intention is to poll that using AJAX and parse it into the position
    of needles on dials in a web page.

    I used to do this via SNMP, but less and less is available with SNMP and
    its clunky as shit,

    If any of that is in /proc or /sys. I would like to hear about it.

    None of this is precision stuff: I am building an ARM based NAS and I
    just need a quick and easy way to keep an eye on it to see if it gets to
    hot or too full as I develop stuff





    It seems to me that the only thing that needs root is smartctl, so

    1) add www (www-data?) to disk group - sudo usermod -a -G disk www(-data)
    2) add CAP_SYS_RAWIO to smartctl - sudo setcap 'cap_sys_rawio=ep' /usr/sbin/smartctl

    Suggestion: assuming /usr/bin is in path but /usr/sbin isn't
    #!/bin/bash
    for i in /dev/sd?; do /usr/sbin/smartctl -a "$i" | awk '/Celsius/{print
    $10}'; done
    vcgencmd measure_temp | sed -e "s/temp=//;s/'C//"
    /usr/sbin/ip -s link show dev eth0 | awk 'FNR == 4 || FNR == 6 {print $1}'
    df -h | awk '/^\/dev\// && gsub(" *"," ")'



    --
    Chris Elvidge, England
    BEWITCHED, DOES NOT PROMOTE SATANISM

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to The Natural Philosopher on Sat May 24 15:41:08 2025
    XPost: comp.sys.raspberry-pi

    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid> wrote:
    On 24/05/2025 06:43, c186282 wrote:
    On 5/23/25 8:26 AM, The Natural Philosopher wrote:
    I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

      Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?


      Ummm ... just sayin' ... do you REALLY want/need that ???

      Seems like a recipe for sure disaster.

    Why on earth would you say that?

    Lawrence is usually trolling more often than not.

    If I told you that you didnt need an engine start switch inside your
    car because it was a security hazard, you would be puzzled, too,.

    A killfile entry helps with the "usually trolling" aspect.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eli the Bearded@21:1/5 to invalid@invalid.invalid on Sat May 24 17:55:46 2025
    XPost: comp.sys.raspberry-pi

    In comp.os.linux.misc, Richard Kettlewell <invalid@invalid.invalid> wrote:
    Standard Usenet style when you don't know how to solve someone's problem
    (or didn't understand it) is to argue with their requirements instead.

    To be fair, some questions really do provoke thoughts of "The only
    reason you'd try to solve it that way is because of faulty requirement expectations."

    That's why I try to answer two ways, the way I'd do it for those
    requirements, and the way I'd do it rewriting requirements.

    In this case, I suggested running Apache as root, so all CGIs run as
    root, and also running the root bit from cron and then reading output
    with the CGI.

    Elijah
    ------
    if you don't know how to run things as root, maybe you should not do that

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrew Smallshaw@21:1/5 to The Natural Philosopher on Sat May 24 17:35:55 2025
    XPost: comp.sys.raspberry-pi

    On 2025-05-23, The Natural Philosopher <tnp@invalid.invalid> wrote:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    Bookworm linux on a Pi4.

    Its all inside a domestic firewall so security is not a huge issue.
    What is the quickest and simplest solution to this?

    I have a vague memory of an "shc" package which describes itself
    as a shell script compiler. In reality it isn't but its does
    package up the script in a directly executable format (i.e. ELF)
    and pass it to the shell at runtime. That would allow a SetUID
    flag to work. Seems to be listed as a Debian package but I haven't
    used it in decades.

    --
    Andrew Smallshaw
    andrews@sdf.org

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to Eli the Bearded on Sat May 24 19:24:31 2025
    XPost: comp.sys.raspberry-pi

    Eli the Bearded <*@eli.users.panix.com> writes:
    Richard Kettlewell <invalid@invalid.invalid> wrote:
    Standard Usenet style when you don't know how to solve someone's
    problem (or didn't understand it) is to argue with their requirements
    instead.

    To be fair, some questions really do provoke thoughts of "The only
    reason you'd try to solve it that way is because of faulty requirement expectations."

    Oh yes, some people seem to have incredibly strange requirements. I have (perhaps not entirely l-) managed to learn to resist arguing with them,
    it only took a few decades...

    if you don't know how to run things as root, maybe you should not do that

    I have on, a number of occasions, found myself cleaning up the mess
    resulting from someone having been given a technological tool they
    didn’t really know how to use. (And at least once had to get a tradesman
    in to sort out a mess of my own creation, but the less said about that
    the better.)

    --
    https://www.greenend.org.uk/rjk/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Fritz Wuehler@21:1/5 to All on Sat May 24 23:34:48 2025
    Andrew Smallshaw <andr...@sdf.org> [AS]:
    I have a vague memory of an "shc" package which describes itself
    as a shell script compiler. In reality it isn't but it does
    package up the script in a directly executable format (i.e. ELF)
    and pass it to the shell at runtime. That would allow a SetUID
    flag to work.

    Nope.

    The 'shc' generated executable will first decrypt/validate itself and
    then launch behind the scenes whatever shell was specified as
    its option (or the default shell), feeding it with the original
    shell script. The kernel will still not honour the setuid bit.

    'shc' was written as a way to obfuscate/ensure the integrity of
    released shell scripts, it doesn't parse/understand the script
    commands itself, thus it's useless in the OP's scenario.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Anssi Saari on Sun May 25 08:52:46 2025
    XPost: comp.sys.raspberry-pi

    On 25/05/2025 08:17, Anssi Saari wrote:
    The Natural Philosopher <tnp@invalid.invalid> writes:

    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.

    I think lm-sensors. I have a compute module 3+ variant running but same
    SoC anyways and lm-sensors gives this:

    cpu_thermal-virtual-0
    Adapter: Virtual device
    temp1: +52.1°C

    Ah I didn't know lm-sensors existed for ARM

    I don't have drives other than the eMMC on the Pi but on my router for example lm-sensors gives:

    drivetemp-scsi-0-0
    Adapter: SCSI adapter
    temp1: +50.0°C

    That's for an mSATA SSD.

    Sadly USB attached SSDS do not show up...

    Plus data on the amount of data being transported over the ethernet
    interface.

    /sys/class/net/eth0/statistics

    That is handy.


    --
    "It is an established fact to 97% confidence limits that left wing
    conspirators see right wing conspiracies everywhere"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anssi Saari@21:1/5 to The Natural Philosopher on Sun May 25 10:17:01 2025
    XPost: comp.sys.raspberry-pi

    The Natural Philosopher <tnp@invalid.invalid> writes:

    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.

    I think lm-sensors. I have a compute module 3+ variant running but same
    SoC anyways and lm-sensors gives this:

    cpu_thermal-virtual-0
    Adapter: Virtual device
    temp1: +52.1C

    I don't have drives other than the eMMC on the Pi but on my router for
    example lm-sensors gives:

    drivetemp-scsi-0-0
    Adapter: SCSI adapter
    temp1: +50.0C

    That's for an mSATA SSD.

    Plus data on the amount of data being transported over the ethernet interface.

    /sys/class/net/eth0/statistics

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to The Natural Philosopher on Sun May 25 09:42:32 2025
    XPost: comp.sys.raspberry-pi

    On Sun, 25 May 2025 08:52:46 +0100, The Natural Philosopher wrote:

    Sadly USB attached SSDS do not show up...

    Try smartctl(8) for them.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anssi Saari@21:1/5 to The Natural Philosopher on Mon May 26 11:27:55 2025
    XPost: comp.sys.raspberry-pi

    The Natural Philosopher <tnp@invalid.invalid> writes:

    Sadly USB attached SSDS do not show up...

    I suppose it needs support from the drives and whatever USB-ATA
    translator is in use. Seems a little odd though that smartctl works and
    this doesn't.

    The kernel driver for this is called drivetemp so it's worth checking if
    it's loaded or if manually loading that driver changes anything.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Anssi Saari on Mon May 26 12:31:16 2025
    XPost: comp.sys.raspberry-pi

    On 26/05/2025 09:27, Anssi Saari wrote:
    The Natural Philosopher <tnp@invalid.invalid> writes:

    Sadly USB attached SSDS do not show up...

    I suppose it needs support from the drives and whatever USB-ATA
    translator is in use. Seems a little odd though that smartctl works and
    this doesn't.

    Smartctl is a very generic interrogation. I suspect that the more
    intimately connected NVMe is accessible by other means than ATA commands

    As I have repeatedly said. I stop at the first workable solution I find. Smarctl works.


    The kernel driver for this is called drivetemp so it's worth checking if
    it's loaded or if manually loading that driver changes anything.

    It's no big deal. I have a solution that is *good enough* thanks to
    hints given here.
    And if I need to add another command that needs root access, I can
    easily do it.




    --
    “Puritanism: The haunting fear that someone, somewhere, may be happy.”

    H.L. Mencken, A Mencken Chrestomathy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dominik =?UTF-8?Q?A=C5=82aszewski?=@21:1/5 to All on Mon May 26 17:24:20 2025
    Dnia 23.05.2025 The Natural Philosopher <tnp@invalid.invalid> napisał/a:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    One can consider communicating via files. Apache writes a file
    in a certain location (perhaps with the arguments for the script),
    script run (as root) is then triggered via inotify mechanism (one can utilise i.e. incron),
    the results are written to another file, readable by Apache.

    --
    Dominik Ałaszewski (pi/Debian/slrn)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to All on Mon May 26 20:44:58 2025
    On 26/05/2025 18:24, Dominik Ałaszewski wrote:
    Dnia 23.05.2025 The Natural Philosopher <tnp@invalid.invalid> napisał/a:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    One can consider communicating via files. Apache writes a file
    in a certain location (perhaps with the arguments for the script),
    script run (as root) is then triggered via inotify mechanism (one can utilise i.e. incron),
    the results are written to another file, readable by Apache.

    Why make stuff more complicated than it has to be?

    --
    Civilization exists by geological consent, subject to change without notice.
    – Will Durant

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to The Natural Philosopher on Mon May 26 22:22:56 2025
    On Mon, 26 May 2025 20:44:58 +0100, The Natural Philosopher wrote:

    On 26/05/2025 18:24, Dominik Ałaszewski wrote:

    One can consider communicating via files. Apache writes a file in a
    certain location (perhaps with the arguments for the script),
    script run (as root) is then triggered via inotify mechanism (one can
    utilise i.e. incron),
    the results are written to another file, readable by Apache.

    Why make stuff more complicated than it has to be?

    Separation of privileges.

    Replace “file + inotify” with “unix socket”, and you have a simpler solution that still maintains the same separation of privileges.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From c186282@21:1/5 to All on Tue May 27 01:48:34 2025
    On 5/26/25 1:24 PM, Dominik Ałaszewski wrote:
    Dnia 23.05.2025 The Natural Philosopher <tnp@invalid.invalid> napisał/a:
    I have a shell script that monitors hardware stuff - it needs to run as
    root and be called by Apache as user www.

    One can consider communicating via files. Apache writes a file
    in a certain location (perhaps with the arguments for the script),
    script run (as root) is then triggered via inotify mechanism (one can utilise i.e. incron),
    the results are written to another file, readable by Apache.

    Done that - and it WORKS.

    A bit 'convoluted' true, but it's fairly secure.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From druck@21:1/5 to Anssi Saari on Tue May 27 21:44:07 2025
    XPost: comp.sys.raspberry-pi

    On 26/05/2025 09:27, Anssi Saari wrote:
    The Natural Philosopher <tnp@invalid.invalid> writes:
    Sadly USB attached SSDS do not show up...

    I suppose it needs support from the drives and whatever USB-ATA
    translator is in use. Seems a little odd though that smartctl works and
    this doesn't.

    There are parameters you can supply which may allow it to work. Do a
    lsusb to get the adapter name and search for it and smartctl. If it's a
    must have get another adapter which is known to work with smartctl.

    ---druck

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to druck on Wed May 28 08:58:58 2025
    XPost: comp.sys.raspberry-pi

    On 27/05/2025 21:44, druck wrote:
    On 26/05/2025 09:27, Anssi Saari wrote:
    The Natural Philosopher <tnp@invalid.invalid> writes:
    Sadly USB attached SSDS do not show up...

    I suppose it needs support from the drives and whatever USB-ATA
    translator is in use. Seems a little odd though that smartctl works and
    this doesn't.

    There are parameters you can supply which may allow it to work. Do a
    lsusb to get the adapter name and search for it and smartctl. If it's a
    must have get another adapter which is known to work with smartctl.

    It does work with smartcl, Not with lm-sensors

    #sensors
    cpu_thermal-virtual-0
    Adapter: Virtual device
    temp1: +55.5°C

    rpi_volt-isa-0000
    Adapter: ISA adapter
    in0: N/A

    but
    #smartctl -a /dev/sda | grep -i temp
    194 Temperature_Celsius 0x0022 061 050 000 Old_age Always
    - 39 (Min/Max 16/50)


    --
    “it should be clear by now to everyone that activist environmentalism
    (or environmental activism) is becoming a general ideology about humans,
    about their freedom, about the relationship between the individual and
    the state, and about the manipulation of people under the guise of a
    'noble' idea. It is not an honest pursuit of 'sustainable development,'
    a matter of elementary environmental protection, or a search for
    rational mechanisms designed to achieve a healthy environment. Yet
    things do occur that make you shake your head and remind yourself that
    you live neither in Joseph Stalin’s Communist era, nor in the Orwellian utopia of 1984.”

    Vaclav Klaus

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From druck@21:1/5 to The Natural Philosopher on Wed May 28 21:34:19 2025
    XPost: comp.sys.raspberry-pi

    On 28/05/2025 08:58, The Natural Philosopher wrote:
    On 27/05/2025 21:44, druck wrote:
    It does work with smartcl, Not with lm-sensors

    Sorry, picked up on the wrong part of the post.

    lm-sensors wont work with external USB drives as it only knows about
    things connected to the internal busses of a machine such as acpi and
    i2c, and the Pi only had the latter.

    If you really want to measure the disc's temperature using lm-sensors,
    you could attach a i2c temperature sensor to it and add a device tree
    entry so it is detected. See:- https://www.bergzand.net/the-raspberry-pi-a-temperature-sensor-and-the-device-tree.html

    But unless you are using the external drive somewhere with an incredibly
    high ambient temperature, it's very unlikely to overheat. The only hard
    drive I had problems with was inside a DVR in a rack of other equipment
    in an enclosed space. I had to tweak the fan configuration to keep it
    under it's alert temperature of 55C.

    ---druck

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From vallor@21:1/5 to ldo@nz.invalid on Thu May 29 03:04:02 2025
    XPost: comp.sys.raspberry-pi

    On Sun, 25 May 2025 09:42:32 -0000 (UTC), Lawrence D'Oliveiro
    <ldo@nz.invalid> wrote in <100uom7$1aabi$1@dont-email.me>:

    On Sun, 25 May 2025 08:52:46 +0100, The Natural Philosopher wrote:

    Sadly USB attached SSDS do not show up...

    Try smartctl(8) for them.

    Good call, but may need to specify a bridge for an external SSD,
    e.g.:

    # smartctl -d sntasmedia -a /dev/sda
    smartctl 7.4 2023-08-01 r5530 [x86_64-linux-6.15.0] (local build)
    Copyright (C) 2002-23, Bruce Allen, Christian Franke, www.smartmontools.org

    === START OF INFORMATION SECTION ===
    Model Number: WD_BLACK SN850XE 4000GB
    [...]
    Temperature: 31 Celsius
    [...]

    Note that finding the right bridge could be a bit of a chore...

    --
    -v System76 Thelio Mega v1.1 x86_64 NVIDIA RTX 3090 Ti
    OS: Linux 6.15.0 Rel: Mint 22.1 wm: Xfce 4.18 Mem: 258G
    "Old age is better than the alternative."

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anssi Saari@21:1/5 to druck on Thu May 29 10:07:42 2025
    XPost: comp.sys.raspberry-pi

    druck <news@druck.org.uk> writes:

    On 28/05/2025 08:58, The Natural Philosopher wrote:
    On 27/05/2025 21:44, druck wrote:
    It does work with smartcl, Not with lm-sensors

    Sorry, picked up on the wrong part of the post.

    lm-sensors wont work with external USB drives as it only knows about
    things connected to the internal busses of a machine such as acpi and
    i2c, and the Pi only had the latter.

    No. See for example here: https://www.kernel.org/doc/html/latest/hwmon/drivetemp.html, the
    drivetemp driver uses ATA commands to read temperatures from drives or alternatively, using SMART attributes. lm-sensors either uses the
    drivetemp kernel driver or just reads from /sys/class/hwmon.

    Which is why I said before, I find it odd if smartctl works and
    drivetemp does not, although AFAiK no one has actually tried that in
    this thread.

    Unfortunately I don't have any recent USB HDs around. I do have an
    USB-SSD case but don't have a spare SSD to put into it right now.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to vallor on Thu May 29 12:03:02 2025
    XPost: comp.sys.raspberry-pi

    On 29/05/2025 04:04, vallor wrote:
    On Sun, 25 May 2025 09:42:32 -0000 (UTC), Lawrence D'Oliveiro <ldo@nz.invalid> wrote in <100uom7$1aabi$1@dont-email.me>:

    On Sun, 25 May 2025 08:52:46 +0100, The Natural Philosopher wrote:

    Sadly USB attached SSDS do not show up...

    Try smartctl(8) for them.

    Good call, but may need to specify a bridge for an external SSD,
    e.g.:


    I don't.

    smartctl -a /dev/sd[ab] works fine...

    And in the end solving the 'root script' problem was simpler than
    solving the 'how do I read the disk temp without root' problem.



    --
    “Politics is the art of looking for trouble, finding it everywhere, diagnosing it incorrectly and applying the wrong remedies.”
    ― Groucho Marx

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to druck on Thu May 29 11:36:57 2025
    XPost: comp.sys.raspberry-pi

    On 28/05/2025 21:34, druck wrote:
    On 28/05/2025 08:58, The Natural Philosopher wrote:
    On 27/05/2025 21:44, druck wrote:
    It does work with smartcl, Not with lm-sensors

    Sorry, picked up on the wrong part of the post.

    lm-sensors wont work with external USB drives as it only knows about
    things connected to the internal busses of a machine such as acpi and
    i2c, and the Pi only had the latter.

    If you really want to measure the disc's temperature using lm-sensors,
    you could attach a i2c temperature sensor to it and add a device tree
    entry so it is detected. See:- https://www.bergzand.net/the-raspberry-pi-a-temperature-sensor-and-the-device-tree.html

    But unless you are using the external drive somewhere with an incredibly
    high ambient temperature, it's very unlikely to overheat. The only hard
    drive I had problems with was inside a DVR in a rack of other equipment
    in an enclosed space. I had to tweak the fan configuration to keep it
    under it's alert temperature of 55C.

    The drives in question will be in an enclosure with the fanless Pi 4,
    and so far have peaked at over 60°C when they are rated only up to 70°C ambient.
    And I have had issues under heavy load but I strongly suspect these are
    power supply related not temperature.The reason for the monitor is to
    try and see if there is any correlation between temperature and
    temporary drive failure.

    I will probably stick a scope on the USB power rails at some time to
    look for issues there.



    ---druck

    --
    The theory of Communism may be summed up in one sentence: Abolish all
    private property.

    Karl Marx

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Anssi Saari on Thu May 29 12:14:09 2025
    XPost: comp.sys.raspberry-pi

    On 29/05/2025 08:07, Anssi Saari wrote:
    druck <news@druck.org.uk> writes:

    On 28/05/2025 08:58, The Natural Philosopher wrote:
    On 27/05/2025 21:44, druck wrote:
    It does work with smartcl, Not with lm-sensors

    Sorry, picked up on the wrong part of the post.

    lm-sensors wont work with external USB drives as it only knows about
    things connected to the internal busses of a machine such as acpi and
    i2c, and the Pi only had the latter.

    No. See for example here: https://www.kernel.org/doc/html/latest/hwmon/drivetemp.html, the
    drivetemp driver uses ATA commands to read temperatures from drives or alternatively, using SMART attributes. lm-sensors either uses the
    drivetemp kernel driver or just reads from /sys/class/hwmon.

    I checked and drivetemp module is invoked in the kernel.

    # zgrep -i temp /boot/config-6.12.25+rpt-rpi-2712
    # CONFIG_SYSTEMPORT is not set
    CONFIG_SENSORS_DRIVETEMP=m
    # Temperature sensors
    # end of Temperature sensors

    But I have no idea how to access anything with it.

    Which is why I said before, I find it odd if smartctl works and
    drivetemp does not, although AFAiK no one has actually tried that in
    this thread.

    How does one 'use' drivetemp?

    Unfortunately I don't have any recent USB HDs around. I do have an
    USB-SSD case but don't have a spare SSD to put into it right now.

    PiOS is always a little bit 'a road less debugged' than
    *x86...especially in terms of stuff that accesses hardware.

    It reminds me of mainstream Linux 10 years ago. And hacking UDEV to get
    it to recognise a camera.

    These days it JustWorks™

    --
    A lie can travel halfway around the world while the truth is putting on
    its shoes.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to The Natural Philosopher on Thu May 29 14:41:10 2025
    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid> wrote:
    The drives in question will be in an enclosure with the fanless Pi 4,
    and so far have peaked at over 60°C when they are rated only up to
    70°C ambient.

    Take note of the fact that drives (I'm assuming by 'drives' you mean
    'spinning rust') often have much longer lifetimes if they are kept
    cool.

    You may want to find a way to rig a fan to provide some airflow over
    those drives (it is amazing how much difference even a small airflow
    will make).

    For noise abatement on the fan, one of the easiest ways to reduce fan
    noise is to run a 12v fan on 7v. Most of them will start and run (at a
    much lower RPM) on 7v. And you get 7v by connecting the fan positive
    to the PSU 12v rail and the fan negative to the 5v rail (if you have
    'spinning rust' drives then you have 12v and 5v supply rails for the
    drives).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Rich on Thu May 29 18:47:41 2025
    On 29/05/2025 15:41, Rich wrote:
    In comp.os.linux.misc The Natural Philosopher <tnp@invalid.invalid> wrote:
    The drives in question will be in an enclosure with the fanless Pi 4,
    and so far have peaked at over 60°C when they are rated only up to
    70°C ambient.

    Take note of the fact that drives (I'm assuming by 'drives' you mean 'spinning rust') often have much longer lifetimes if they are kept
    cool.

    No. They are 2TB SSDs

    You may want to find a way to rig a fan to provide some airflow over
    those drives (it is amazing how much difference even a small airflow
    will make).

    For noise abatement on the fan, one of the easiest ways to reduce fan
    noise is to run a 12v fan on 7v. Most of them will start and run (at a
    much lower RPM) on 7v. And you get 7v by connecting the fan positive
    to the PSU 12v rail and the fan negative to the 5v rail (if you have 'spinning rust' drives then you have 12v and 5v supply rails for the
    drives).

    Since I will be printing the case it all goes in, if it needs a fan I
    can add one

    --
    Climate Change: Socialism wearing a lab coat.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anssi Saari@21:1/5 to The Natural Philosopher on Fri May 30 20:53:00 2025
    XPost: comp.sys.raspberry-pi

    The Natural Philosopher <tnp@invalid.invalid> writes:

    How does one 'use' drivetemp?

    Load it with modprobe and data appears in /sys/class/hwmon somewhere. It doesn't seem to autoload always, I don't know what the trigger is. For
    example, on my router it's loaded, on my little pizza box it's not.

    For example, on the pizza box, /sys/class/hwmon/hwmon2/temp1_input
    appears after loading drivetemp and it contains 36000 which means 36
    degrees C.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Anssi Saari on Fri May 30 19:36:18 2025
    XPost: comp.sys.raspberry-pi

    On 30/05/2025 18:53, Anssi Saari wrote:
    The Natural Philosopher <tnp@invalid.invalid> writes:

    How does one 'use' drivetemp?

    Load it with modprobe and data appears in /sys/class/hwmon somewhere. It doesn't seem to autoload always, I don't know what the trigger is. For example, on my router it's loaded, on my little pizza box it's not.

    For example, on the pizza box, /sys/class/hwmon/hwmon2/temp1_input
    appears after loading drivetemp and it contains 36000 which means 36
    degrees C.

    Doesnt find the drives. Looks like its found the CPU temp though
    Oh well. Thanks for trying


    --
    It is the folly of too many to mistake the echo of a London coffee-house
    for the voice of the kingdom.

    Jonathan Swift

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Narkiewicz@21:1/5 to The Natural Philosopher on Wed Jun 4 08:18:01 2025
    XPost: comp.sys.raspberry-pi

    The Natural Philosopher <tnp@invalid.invalid> writes:

    I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

    doas /path/to/shell.sh
    or sudo.

    Things are going to be a bit more complicated if you're in chroot.
    A small C utility that wraps exec and provides suid should be ok.

    Another way is to call the script form cron and place the output
    in some location where apache can get it.

    Best regards,
    Chris Narkiewicz

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Chris Narkiewicz on Wed Jun 4 13:12:21 2025
    On 04/06/2025 08:18, Chris Narkiewicz wrote:
    The Natural Philosopher <tnp@invalid.invalid> writes:

    I have a shell script that monitors hardware stuff - it needs to run
    as root and be called by Apache as user www.

    doas /path/to/shell.sh
    or sudo.

    In the end setting a passwordless sudo for the www-data user for that
    script only, worked and was the first method to do so, so I stopped there.


    Things are going to be a bit more complicated if you're in chroot.
    A small C utility that wraps exec and provides suid should be ok.

    I have done that in the past.

    Another way is to call the script form cron and place the output
    in some location where apache can get it.

    I want very fast up to date response when I am on the web site and dont
    care when I am not, so that inclines towards a real time script.

    Best regards,
    Chris Narkiewicz

    --
    It is the folly of too many to mistake the echo of a London coffee-house
    for the voice of the kingdom.

    Jonathan Swift

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)