bug-bash
[Top][All Lists]
Advanced

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

Please advise on bash programming tactics/strategy


From: cga2000
Subject: Please advise on bash programming tactics/strategy
Date: Tue, 11 Dec 2007 22:39:24 -0500
User-agent: Mutt/1.5.13 (2006-08-11)

I was wondering if there is any way I can convince netstat to return
its output to bash variables for additional processing.

Pretty simple logic:

Do forever:

  Call netstat to obtain RX & TX byte counts for eth0
  Print delta {current .. minus previous .. byte counts}
  Save current byte counts 
  Wait for a second or so ..

I initially thought I could just pipe the "netstat -in" command to the
invocation of a bash function.

The function would have taken care of the gory details of parsing &
formatting the output of the netstat command and then stored the current
byte counts where they would be available for the next time the function
is invoked.

The trouble is that I haven't been able to find anything like a "static"
local variable -- ie. variables that are not reinitialized every time
the function is invoked.

Is there such a thing?

Or is there any way the function could save the current byte counts to
global variables?  

Naturally, I thought of using an array but, at least as I understand it,
the bash doc seems to indicate that even with arrays, function calls
result in the array's contents being copied to a local copy that only
lives for the the duration of the current invocation of the function.

Or is there an altogether better .. more natural way to do the above in
bash?

Hope the above makes sense .. Will clarify if necessary.

:-)










reply via email to

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