home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 15111 < prev    next >
Encoding:
Internet Message Format  |  1993-01-02  |  2.2 KB

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