|
From: | Michael Mehari |
Subject: | Re: [Help-bash] How to monitor bash variables periodically |
Date: | Fri, 30 Jan 2015 15:49:50 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
Thank you for the explanation Greg,As you have pointed out, storing the variable to a file from a loop works and i had been using this solution for long. However, i want to create an automatic variable monitoring system, such that the user passes the name of the variable and the program internally grabs its value as time progresses. So for the user, all he/she will do is specify the variable name and monitoring interval therefore writing the variable with in a loop is not what i am looking for.
Another option i am looking recently is using shared memories. The main program where the user writes will have its monitor variables in shared memory (e.g. /dev/shm/filexxx) and a child process periodically reads this value and store it in a file. This looks feasible except that i want the reading and writing to this shared memory be as simple as accessing any variable since the user will consider it as normal variable.
Any ides towards this direction. Thanks for the help again and kind regards, Michael On 01/26/2015 06:41 PM, Greg Wooledge wrote:
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 address@hidden, not bug-bash. I've Cc'ed the correct list.
-- Michael Mehari Department of Information Technology Internet Based Communication Networks and Services (IBCN) Ghent University - iMinds Gaston Crommenlaan 8 (Bus 201), B-9050 Gent, Belgium Mob: +32 476 38 49 07 Tel: +32 (0)9 33 13800 Fax: +32 (0)9 33 14899 E-mail: address@hidden Web: www.ibcn.intec.UGent.be
[Prev in Thread] | Current Thread | [Next in Thread] |