home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.admin
- Path: sparky!uunet!wupost!psuvax1!news.cc.swarthmore.edu!ralph.cs.haverford.edu!eoliver
- From: eoliver@ralph.cs.haverford.edu (Erik Oliver)
- Subject: Re: How to write a "turnin" utility??
- Message-ID: <0V5VBS2D@cc.swarthmore.edu>
- Sender: news@cc.swarthmore.edu (USENET News System)
- Nntp-Posting-Host: ralph.cs.haverford.edu
- Organization: Haverford College Computer Science Department
- References: <1992Dec28.213900.14908@organpipe.uug.arizona.edu> <1992Dec29.015418.12223@doug.cae.wisc.edu>
- Distribution: world
- Date: Tue, 29 Dec 1992 15:24:08 GMT
- Lines: 55
-
- Ummmmmm...
-
- While, I agree that that is the basic idea, there need to be some
- precautions taken to avoid user overwriting existing files.
-
- The script should most definitely check for an existing file and then
- refuse the copy... The script should probably be either Set UID or Set
- GID though.
-
- Also, to the original poster, I think your attitude about shell scripts
- is a little unwarented. Also, there is the final option of creating a
- new group and giving instructors privs to read things in that group...
-
- Here is another example, a sh script which does a little more error
- checking and gives an example of how to handle multiple paramteres, eg
- file names. I can't guaranteee its accuracy because I just whipped it
- together, but I think the basic framework is what you need.
- The protection against overwriting files with data, -s $1, is essential
- otherwise a malicious person could overwrite other people's assignments,
- perhaps even inadvertantly.
-
- I suspect that there might be some other issues though like creating
- subdirectories for each student's work to fall into and more. If you
- would like more help with stuff like that, let me know.
-
- -Erik
- ########
- Shell script starts below:
-
- #!/bin/sh
- #
- # Turn in Utility
- destdir=/usr/courses/completedhwk/
-
- if [ $# < 1 ]
- then
- # if they didn't list at least one file name, then tell them
- # how to use the command.
- echo "Usage: turnin: turning file1 [file2] [file3] ..."
- exit
- fi
-
- while [ "$1" ]
- do
- # if the filename is non-null...
- if [ -s $1]
- then
- echo "Can't overwrite existing file named: $1"
- else
- cp $1 $destdir
- fi
- shift
- # move the paramters over and start again
- done
-
-