TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: MARTIN GREGORIE
from: PANCHO
date: 2021-01-16 12:24:00
subject: Re: Battery Powered Proje

On 13/01/2021 15:12, Martin Gregorie wrote:
> On Wed, 13 Jan 2021 13:56:52 +0000, The Natural Philosopher wrote:
>
>> On 12/01/2021 16:40, Pancho wrote:
>>> On 12/01/2021 12:14, Simple Simon wrote:
>>>> I am working on a battery powered car and want the Pi to shut down
>>>> automatically if the battery starts to go flat to try to prevent SD
>>>> card corruption. I am a beginner to bash scripts! I will run this via
>>>> crontab...
>>>>
>>>> #!/bin/bash powerstatus=$(vcgencmd get_throttled)
>>>> if [ $powerstatus="throttled=0x1" ]
>>>> then echo Under Voltage Detected - Shutting Down sudo halt else echo
>>>> Voltage Normal fi
>>>>
>>>> Obviously it is not working!! Could someone correct and explain for me
>>>> please.
>>>
>>> Not being much help, but...
>>>
>>> I'm aware of Under Voltage problems from entries in journalctl. It
>>> seems to me that listening for events logged to journalctl would be a
>>> pretty common thing to do. So common that there should be some standard
>>> way of doing it. Some kind of standard Observer pattern on jounalctl.
>>> Does anyone know of one?
>>
> One way to get a rapid notification of entries written to a log is the
> use 'tail' in a script.
>
> Running "sudo tail -f /var/log/messages" from a console shows you each
> message as it is written to /var/log/messages, so a script started a boot
> time to run with sufficient privilege to read those log entries could
> easily use tail to read messages as they are written and filter out the
> ones of interest with grep or awk and use them to , for instance force a
> clean shutdown on low battery, something like
>
> #!/bin/bash
> tail -f /var/log/messages | awk < /Under voltage/ {  shutdown -h NOW }
> ENDPROG
>

I thought << was a way of redirecting stdin, not redirecting command
line or program file.

But perhaps more importantly, Linux seems to buffer pipelines, meaning
an event watcher on the journal isn't close to immediate.

In fact I couldn't get the following to work at all:

sudo journalctl -f | awk '{ print $0 }'

Let alone anything more ambitious.

Also, although I've read that Unix pipe lines should work as a "push
queue" event mechanism they always feel like a busy loop pull to me.

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.