bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to monitor bash variables periodically


From: Greg Wooledge
Subject: Re: How to monitor bash variables periodically
Date: Mon, 26 Jan 2015 12:41:10 -0500
User-agent: Mutt/1.4.2.3i

On Mon, Jan 26, 2015 at 04:29:04PM +0100, Michael Mehari wrote:
> What i meant by 
> variable monitoring is to periodically read variable values and store it 
> to a file for later processing.

> The first approach i looked was to export this variable into the child 
> process and periodically store it from the child process. The problem is 
> the child process gets the variable when it is spawned and does not have 
> its updates as time progresses.

That's correct.  This approach is doomed.

Does your script have some sort of "main loop"?  If so, you should
write your variables to the file as part of that loop.  You can
even use the SECONDS variable to see how long it has been since your
last write, to avoid spamming disk I/O.

Otherwise, you run into the problem that a bash script which *is not*
looping is probably waiting for some foreground child process (or
pipeline) to terminate.  Bash won't do ANYTHING until that happens,
with the possible exception of receiving a signal and calling a
signal handler.  However, even that's not guaranteed.  It only works
if Bash is waiting on a builtin to finish, not arbitrary command or
pipelines.

And even if you did use a signal handler, the correct approach would be
to set a single variable within the handler which tells your script to
do stuff on the next iteration of its main loop.

This belongs on help-bash@gnu.org, not bug-bash.  I've Cc'ed the correct
list.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]