home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!ub4b!news.cs.kuleuven.ac.be!blekul11!ffaac09
- Organization: K.U.Leuven - Academic Computing Center
- Date: Thursday, 3 Sep 1992 22:35:16 +02
- From: Paul Bijnens <FFAAC09@cc1.kuleuven.ac.be>
- Message-ID: <92247.223516FFAAC09@cc1.kuleuven.ac.be>
- Newsgroups: comp.unix.shell
- Subject: Re: Could someone help me with script?
- References: <1992Sep3.151142.27136@u.washington.edu>
- Lines: 112
-
-
- In article <1992Sep3.151142.27136@u.washington.edu>,
- micah@hardy.u.washington.edu (Micah Anderson) says:
- >
- >I run the They Might Be Giants mailing list which has over 260 users on
- >it, I am trying to make it much easier for me to subscribe and unsubscibe
- >users, I wrote this script to make the addition of users easier, but it
- >doesn't always work... comments are in brakets.
- >
- >#/bin/sh
-
- You probably mean "#!/bin/sh" (with a "!"), but it probably works
- without that also.
-
- >#new.exe - adds new users to master list and mails them info files
-
- From the pc-world, he. I just hate suffixes for executable programs.
-
- >#look for duplicates in new list and remove
- >[what I do is go through all my mail and put all the addresses of people
- >who want to subscribe into a file called new, I want to check to see that
- >I don't have the same address in more than once - the problem with this
- >is if there is no duplicate address and the file new.uniq is empty, it just
- >sits there... any suggestions?]
- >
- >sort new > new.sort
- >uniq -d new.sort > new.uniq
- >grep -v `cat new.uniq` new.sort > new.tmp
- >cat new.uniq >> new.tmp
- >rm new.uniq
- >rm new.sort
-
- Why not just: "sort -u -o new new"?
-
- >#mail info files to new users
- >mail `cat new.tmp` < Welcome
- >mail `cat new.tmp` < tmbg.info
- >
- >#add new users to master list
- >cat new.tmp >> /com/mailer/TMBG/USERS
-
- You can combine this into the following step...
-
- >#check for duplicates in master list and remove
- >[here I am attempting to do the same thing as above, looking for duplicate
- >addresses, if an address is in more than once they get twice as much mail,
- >and is a big hassle...]
- >
- >sort /com/mailer/TMBG/USERS > /com/mailer/TMBG/USERS.sort
- >uniq -d /com/mailer/TMBG/USERS.sort > /com/mailer/TMBG/USERS.uniq
- >grep -v `cat /com/mailer/TMBG/USERS.uniq` /com/mailer/TMBG/USERS.sort > p
- >USRS.tm
- >cat /com/mailer/TMBG/USERS.uniq >> USRS.tmp
- >mv USRS.tmp /com/mailer/TMBG/USERS
- >rm /com/mailer/TMBG/USERS.sort
- >rm USRS.tmp
-
- Add to master list, and remove doubles:
-
- MASTERLIST=/com/mailer/TMBG/USERS
- sort -u -o $MASTERLIST new $MASTERLIST
-
- (Making the variable just to avoid typing pathnames too much. Move
- the variable to the front of the script, where you can see it easily
- and change it once if the masterfile changes.)
-
- >#output info to the log
- >[here I would like to also output errors (duplicate addresses) into the file
- >uniq -c will give me a 2 infront of any address that is repeated, BUT if
- >an address has a 2 in it, I cannot grep for the 2... here to explain a little
- >better:
- >Ok, I am attempting to log when I have duplicates in a file, so I have this:
- >
- >uniq -c new.sort|grep 2 > new.log
-
- Hey! "new.sort" is already removed a few lines back...
- So, you probably should do the logging earlier.
-
- >and I get something like:
- >
- > more new.log
- > 2 kavitzp@nickel.brooks.af.mil
- > 1 xgg2356@dcmdc.dla.mil
- >
- >the first one is fine (as there were two of those and I needed to know that)
- >but the second one just has a 2 in the address... how can I check just for the
- >number in the beginning?]
-
- For the number 2 in the beginning: "grep '^2' new.sort", but...
- what if you have a 3 instead of a 2?
- You need something like: "uniq -c new.sort | awk '$1 > 1' > new.log
- Or if you do it in the beginning, before new.sort is made:
-
- sort new | uniq -c | awk '$1 > 1' > new.log
- (and I think you mean ... >> new.log ???)
-
- >date >> new.log
- >wc -l new >> new.log
- >echo ' ' >> new.log
- >cat new >> new.log
- >echo '------------------------------'>> new.log
- >rm new.tmp
-
- How about this:
-
- (date; wc -l new; echo; cat new; echo --------------------) >> new.log
-
- >any comments or suggestions to make this better are more than appreciated!
- --
- Paul Bijnens -- MS-DOS is the world's most widespread virus.
- Linguistics dept., K. University Leuven, Belgium
- Polleke@cc1.kuleuven.ac.be
-