Richard Hartmann | 8 Aug 03:31

A generic function/framework/mechanism for regular polling of data?

Hi all,

I was wondering if a function existed that will use a pattern, target
variables, interval & a data source for polling & parsing information
regularly.

For example, this function could be told to poll ACPI power status
every X seconds and put the result into $foo. The same function
could also keep track of unread mail, the temperature of CPU, HDD,
etc and pretty much antything else you can get from a file or
program and put all of those values into variables.

Does any function like this exist?

Richard

Phil Pennock | 10 Aug 15:14

Re: A generic function/framework/mechanism for regular polling of data?

On 2008-08-08 at 03:33 +0200, Richard Hartmann wrote:
> I was wondering if a function existed that will use a pattern, target
> variables, interval & a data source for polling & parsing information
> regularly.
> 
> For example, this function could be told to poll ACPI power status
> every X seconds and put the result into $foo. The same function
> could also keep track of unread mail, the temperature of CPU, HDD,
> etc and pretty much antything else you can get from a file or
> program and put all of those values into variables.
> 
> Does any function like this exist?

Define periodic() and set $PERIOD; every $PERIOD seconds, periodic()
will be called, just before a prompt.  If you don't cause a prompt to be
shown, the function won't be called.

This is done just after precmd() and just before the $WATCH and
$MAILCHECK checks.

There's ALSO a separate list of commands, called after the mailchecks,
maintained by the zsh/sched loadable module.  Those are single-fire
commands, rather than repeating events.

For unread mail, look at $MAILCHECK, $mailpath and the mail_warning
option.  That assumes mbox mail though.

-Phil
Richard Hartmann | 11 Aug 15:31

Re: A generic function/framework/mechanism for regular polling of data?

On Sun, Aug 10, 2008 at 15:14, Phil Pennock
<zsh-workers+phil.pennock <at> spodhuis.org> wrote:

> Define periodic() and set $PERIOD; every $PERIOD seconds, periodic()
> will be called, just before a prompt.  If you don't cause a prompt to be
> shown, the function won't be called.

I knew about periodic(), but rereading my mail, I should have asked
differently. Let me retry :)

What, if any, is the canonical way to parse information from a file
and putting that into variables. Normally, I would just create a bunch
of functions, but ZSH has surprised me too often by providing things
and mechanisms I never thought of, so I wanted to check if there
are any hidden goodies.

Sorry for the confusion,
Richard

PS: Mental note: Cleanly seperate what I know and what I want to
know when asking questions. Do not ask about the whole concept,
only ask about the missing pieces.

Bart Schaefer | 11 Aug 17:16

Re: A generic function/framework/mechanism for regular polling of data?

On Aug 11,  3:31pm, Richard Hartmann wrote:
}
} What, if any, is the canonical way to parse information from a file
} and putting that into variables.

The canonical way is for the file to be a simple series of assignment
statements, possibly with the occasional "typeset" command thrown in.

This is the reason that the shell uses an interpreted language.  If a
way to load variables is all you're looking for, I don't understand why
you're making this into a programming problem.

} PS: Mental note: Cleanly seperate what I know and what I want to
} know when asking questions. Do not ask about the whole concept,
} only ask about the missing pieces.

Well, no.  Context is often quite important.  Frequently the problem
with programming questions is that the questioner wants to fill in a
missing piece when really it's the entire concept that's wrong (or at
least sub-optimal).  At the very least lack of context makes it hard
to frame the right question.

Case in point:  My answer above doesn't seem to accomplish your first
goal, which (I thought) was how to describe to the shell a parser for
information in arbitrary formats from various sources about assorted
system state.  (The answer to which seems to be that no, zsh doesn't
have an internal equivalent of lex/yacc; the closest thing likely is
zregexparse, which is entirely undocumented except for the examples in
_regex_arguments in the completion system.)

(Continue reading)


Gmane