home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!enterpoop.mit.edu!eff!news.byu.edu!hamblin.math.byu.edu!yvax.byu.edu!cunyvm!jlwbc
- Newsgroups: comp.unix.questions,
- Subject: two shellscripts
- Message-ID: <93002.100858JLWBC@CUNYVM.BITNET>
- From: <JLWBC@CUNYVM.BITNET>
- Date: Saturday, 2 Jan 1993 10:08:58 EST
- Organization: City University of New York/ University Computer Center
- Lines: 44
-
- I have two shellscripts which should do the same thing. One works, the other
- doesn't. It seems to do with how many pipes you have. (I know it sounds
- crazy, but bear with me.)
-
- Both start with "netstat" doing an output once every hour.
- (Actually what it does is pump out two headers and a cumulative line, followed
- by the first of the hourly stats. Then it sleeps for an hour before doing
- another. I have to stop it with a "Ctrl-C".)
-
- In the first the second half of the pipe is an "egrep" to remove the headers.
- A second pipe sends "egrep"'s output to an "awk" for further processing: ---
- /usr/ucb/netstat -n -I le0 3600 | egrep -v "input|packets" | awk '
- {
- print $0;
- if ($3 > 0)
- printf("Collision Rate ... %7.4f\n", (100*$5)/$3)
- else printf("No collisions to report\n")
- } '
- ----------------------------------------------------------------------------
-
- In the second I eliminated the "egrep" with some fancy "awk"-ness and have
- just one pipe: -------------------------------------------------------------
- /usr/ucb/netstat -n -I le0 3600 | awk '
- $0 !~ /input/ && $0 !~ /packets/ {
- print $0;
- if ($3 > 0)
- printf("Collision Rate ... %7.4f\n", (100*$5)/$3)
- else printf("No collisions to report\n")
- } '
- ----------------------------------------------------------------------------
-
- The first script does not work as I wanted; the second does. The question is
- why. By the way a modified version of the first script, leaving out the "awk"
- does work.
-
- I suspected that it is because of the way this version of "netstat" works,
- ie, it doesn't flush its output, but what I can't figure out is what this has
- to do with how many pipes you have (as it appears here in this example).
- Can you explain this one to me?
-
- -- john l wynstra
- e-mail: john@its.brooklyn.cuny.edu
- [not jlwbc@cunyvm.cuny.edu -- that's my mainframe account]
- snail-mail: 43-10 Kissena Blvd. 9G, Flushing, N.Y. 11355
-