I was wondering if there is any way I can convince netstat to return its output to bash variables for processing.
Pretty simple logic: Do forever: Call netstat to obtain RX & TX byte counts 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 would then have 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 that is 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. :-)