home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1252 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  2.2 KB

  1. From: gam@netcom.uucp (Gordon Moffett)
  2. Newsgroups: alt.sources,comp.unix.xenix
  3. Subject: uusched.sh: a shell script to replace broken uuscheds
  4. Message-ID: <11614@netcom.UUCP>
  5. Date: 3 May 90 08:15:12 GMT
  6.  
  7. This article introduces two tools, one dependent on the other.
  8. The first is 'shuffle' a randomizer of lines of text; and
  9. the other is 'uusched.sh', a shell script version of /usr/lib/uucp/uusched
  10. which uses 'shuffle' to provide it's list of site names to call in
  11. random order.  Since many Xenix systems have uuscheds that don't work
  12. (core dump, etc) like ours, I wanted to get uusched.sh to that audience
  13. as well.
  14. Choose your followup's "Newsgroups:" and "Subject:" appropriately.
  15.  
  16. The first file in the shar below is 'shuffle', a simple shell script
  17. that is the opposite of sort.  It takes a list of files or standard
  18. input, and prints them out in random order to standard output.
  19. This can be implimented in a number of ways, but this is one of
  20. the most portable versions (thanks to Mickey @ Altos for this one).
  21.  
  22. This has a few entertaining applications:
  23.  
  24. shuffle < /etc/passwd | sed 1q    # pick a user at random
  25.  
  26. shuffle < fortunes | sed 1q    # print a one-liner fortune
  27.  
  28. It also allows for the shell script equivalent of uusched, 'uusched.sh'
  29. the second file in the shar.  We use here on this Xenix 2.3.2 system
  30. because their uusched is broken.
  31.  
  32. I'd like to see other ways of doing what 'shuffle' does, as long as it
  33. allows for completely random results, like the last line of input
  34. being the first line of output.
  35.  
  36. #!/bin/sh
  37. # xshar:    Shell Archiver  (v1.22)
  38. #
  39. #    Run the following text with /bin/sh to create:
  40. #      shuffle
  41. #      uusched.sh
  42. #
  43. sed 's/^X//' << 'SHAR_EOF' > shuffle &&
  44. Xawk "BEGIN { srand($$) } { print int(rand()*1000000), \$0 }" $* |
  45. Xsort -n |
  46. Xsed 's/^[0-9]* //'
  47. SHAR_EOF
  48. chmod 0775 shuffle || echo "restore of shuffle fails"
  49. sed 's/^X//' << 'SHAR_EOF' > uusched.sh &&
  50. X: /bin/sh
  51. XPATH=$PATH:/usr/local/bin; export PATH    # to find shuffle
  52. Xfile=/tmp/uu$$
  53. Xtrap "rm -f $file" 0 1 15
  54. X
  55. Xfor site in `uuname | shuffle`
  56. Xdo
  57. X    uustat -s$site > $file
  58. X    if [ -s $file ]
  59. X    then
  60. X        /usr/lib/uucp/uucico -r1 -s$site
  61. X    fi
  62. Xdone
  63. SHAR_EOF
  64. chmod 0775 uusched.sh || echo "restore of uusched.sh fails"
  65. exit 0
  66.