home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / shell / 3809 < prev    next >
Encoding:
Text File  |  1992-09-03  |  4.2 KB  |  123 lines

  1. Path: sparky!uunet!mcsun!ub4b!news.cs.kuleuven.ac.be!blekul11!ffaac09
  2. Organization: K.U.Leuven - Academic Computing Center
  3. Date: Thursday, 3 Sep 1992 22:35:16 +02
  4. From: Paul Bijnens <FFAAC09@cc1.kuleuven.ac.be>
  5. Message-ID: <92247.223516FFAAC09@cc1.kuleuven.ac.be>
  6. Newsgroups: comp.unix.shell
  7. Subject: Re: Could someone help me with script?
  8. References:  <1992Sep3.151142.27136@u.washington.edu>
  9. Lines: 112
  10.  
  11.  
  12. In article <1992Sep3.151142.27136@u.washington.edu>,
  13. micah@hardy.u.washington.edu (Micah Anderson) says:
  14. >
  15. >I run the They Might Be Giants mailing list which has over 260 users on
  16. >it, I am trying to make it much easier for me to subscribe and unsubscibe
  17. >users, I wrote this script to make the addition of users easier, but it
  18. >doesn't always work... comments are in brakets.
  19. >
  20. >#/bin/sh
  21.  
  22. You probably mean "#!/bin/sh" (with a "!"), but it probably works
  23. without that also.
  24.  
  25. >#new.exe - adds new users to master list and mails them info files
  26.  
  27. From the pc-world, he.  I just hate suffixes for executable programs.
  28.  
  29. >#look for duplicates in new list and remove
  30. >[what I do is go through all my mail and put all the addresses of people
  31. >who want to subscribe into a file called new, I want to check to see that
  32. >I don't have the same address in more than once - the problem with this
  33. >is if there is no duplicate address and the file new.uniq is empty, it just
  34. >sits there... any suggestions?]
  35. >
  36. >sort new > new.sort
  37. >uniq -d new.sort > new.uniq
  38. >grep -v `cat new.uniq` new.sort > new.tmp
  39. >cat new.uniq >> new.tmp
  40. >rm new.uniq
  41. >rm new.sort
  42.  
  43. Why not just:  "sort -u -o new new"?
  44.  
  45. >#mail info files to new users
  46. >mail `cat new.tmp` < Welcome
  47. >mail `cat new.tmp` < tmbg.info
  48. >
  49. >#add new users to master list
  50. >cat new.tmp >> /com/mailer/TMBG/USERS
  51.  
  52. You can combine this into the following step...
  53.  
  54. >#check for duplicates in master list and remove
  55. >[here I am attempting to do the same thing as above, looking for duplicate
  56. >addresses, if an address is in more than once they get twice as much mail,
  57. >and is a big hassle...]
  58. >
  59. >sort /com/mailer/TMBG/USERS > /com/mailer/TMBG/USERS.sort
  60. >uniq -d /com/mailer/TMBG/USERS.sort > /com/mailer/TMBG/USERS.uniq
  61. >grep -v `cat /com/mailer/TMBG/USERS.uniq` /com/mailer/TMBG/USERS.sort >       p
  62. >USRS.tm
  63. >cat /com/mailer/TMBG/USERS.uniq >> USRS.tmp
  64. >mv USRS.tmp /com/mailer/TMBG/USERS
  65. >rm /com/mailer/TMBG/USERS.sort
  66. >rm USRS.tmp
  67.  
  68. Add to master list, and remove doubles:
  69.  
  70.     MASTERLIST=/com/mailer/TMBG/USERS
  71.     sort -u -o $MASTERLIST new $MASTERLIST
  72.  
  73. (Making the variable just to avoid typing pathnames too much.  Move
  74. the variable to the front of the script, where you can see it easily
  75. and change it once if the masterfile changes.)
  76.  
  77. >#output info to the log
  78. >[here I would like to also output errors (duplicate addresses) into the file
  79. >uniq -c will give me a 2 infront of any address that is repeated, BUT if
  80. >an address has a 2 in it, I cannot grep for the 2... here to explain a little
  81. >better:
  82. >Ok, I am attempting to log when I have duplicates in a file, so I have this:
  83. >
  84. >uniq -c new.sort|grep 2 > new.log
  85.  
  86. Hey! "new.sort" is already removed a few lines back...
  87. So, you probably should do the logging earlier.
  88.  
  89. >and I get something like:
  90. >
  91. > more new.log
  92. >      2 kavitzp@nickel.brooks.af.mil
  93. >      1 xgg2356@dcmdc.dla.mil
  94. >
  95. >the first one is fine (as there were two of those and I needed to know that)
  96. >but the second one just has a 2 in the address... how can I check just for the
  97. >number in the beginning?]
  98.  
  99. For the number 2 in the beginning:  "grep '^2' new.sort", but...
  100. what if you have a 3 instead of a 2?
  101. You need something like:   "uniq -c new.sort | awk '$1 > 1' > new.log
  102. Or if you do it in the beginning, before new.sort is made:
  103.  
  104.     sort new | uniq -c | awk '$1 > 1' > new.log
  105.            (and I think you mean  ... >> new.log   ???)
  106.  
  107. >date >> new.log
  108. >wc -l new >> new.log
  109. >echo ' ' >> new.log
  110. >cat new >> new.log
  111. >echo '------------------------------'>> new.log
  112. >rm new.tmp
  113.  
  114. How about this:
  115.  
  116.    (date; wc -l new; echo; cat new; echo --------------------) >> new.log
  117.  
  118. >any comments or suggestions to make this better are more than appreciated!
  119. --
  120. Paul Bijnens             -- MS-DOS is the world's most widespread virus.
  121. Linguistics dept., K. University Leuven, Belgium
  122. Polleke@cc1.kuleuven.ac.be
  123.