home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / admin / 6822 < prev    next >
Encoding:
Text File  |  1992-12-29  |  2.2 KB  |  69 lines

  1. Newsgroups: comp.unix.admin
  2. Path: sparky!uunet!wupost!psuvax1!news.cc.swarthmore.edu!ralph.cs.haverford.edu!eoliver
  3. From: eoliver@ralph.cs.haverford.edu (Erik Oliver)
  4. Subject: Re: How to write a "turnin" utility??
  5. Message-ID: <0V5VBS2D@cc.swarthmore.edu>
  6. Sender: news@cc.swarthmore.edu (USENET News System)
  7. Nntp-Posting-Host: ralph.cs.haverford.edu
  8. Organization: Haverford College Computer Science Department
  9. References: <1992Dec28.213900.14908@organpipe.uug.arizona.edu> <1992Dec29.015418.12223@doug.cae.wisc.edu>
  10. Distribution: world 
  11. Date: Tue, 29 Dec 1992 15:24:08 GMT
  12. Lines: 55
  13.  
  14. Ummmmmm...
  15.  
  16. While, I agree that that is the basic idea, there need to be some
  17. precautions taken to avoid user overwriting existing files.
  18.  
  19. The script should most definitely check for an existing file and then
  20. refuse the copy...  The script should probably be either Set UID or Set
  21. GID though.
  22.  
  23. Also, to the original poster, I think your attitude about shell scripts
  24. is a little unwarented.  Also, there is the final option of creating a
  25. new group and giving instructors privs to read things in that group...
  26.  
  27. Here is another example, a sh script which does a little more error
  28. checking and gives an example of how to handle multiple paramteres, eg
  29. file names.  I can't guaranteee its accuracy because I just whipped it
  30. together, but I think the basic framework is what you need.
  31. The protection against overwriting files with data, -s $1, is essential
  32. otherwise a malicious person could overwrite other people's assignments,
  33. perhaps even inadvertantly.
  34.  
  35. I suspect that there might be some other issues though like creating
  36. subdirectories for each student's work to fall into and more.  If you
  37. would like more help with stuff like that, let me know.
  38.  
  39. -Erik
  40. ########
  41. Shell script starts below:
  42.  
  43. #!/bin/sh
  44. #
  45. # Turn in Utility
  46. destdir=/usr/courses/completedhwk/
  47.  
  48. if [ $# < 1 ]
  49. then
  50. # if they didn't list at least one file name, then tell them
  51. # how to use the command.
  52.     echo "Usage: turnin: turning file1 [file2] [file3] ..."
  53.     exit
  54. fi
  55.  
  56. while [ "$1" ]
  57. do
  58. # if the filename is non-null...
  59.     if [ -s $1]
  60.     then
  61.         echo "Can't overwrite existing file named: $1"
  62.     else
  63.         cp $1 $destdir
  64.     fi
  65. shift
  66. # move the paramters over and start again
  67. done
  68.     
  69.