[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-AnyPerl] opening (creating) files on UNIX



Jake asked:

>I'm having some difficulties porting a MacPerl script to a UNIX server.
>Basically, on the Mac if I want to create a file I just use open(FILE,
>">>filename"). This works fine from the shell on UNIX, but when I try this
>in a CGI script, it doesn't like it. What am I doing wrong?

My first thought is that it is a permissions problem.  Unix defines 
three classes of users: Owner, Group, and World.  Each file and each 
directory (folder) has an owner and a group and grants different 
permissions to these three classes.  (World is anyone regardless of 
group or owner.)

Let's say a directory is owned by Mortimer Snoid (msnoid) who is in 
the Developers group (dev).  Let's say that owner and group are 
allowed to write to that directory, but world is not.  Then when 
Mortimer runs a perl script which creates a file, it works fine. 
However, when he runs it as a CGI, that CGI is running with the owner 
and group of the web server, not of Mortimer, and it cannot create 
the file.

1) You need to know the owner and group of the web server.  www and 
nobody are common for both (e.g. owner www, group www).

2) You need to know the ownership and permissions of the directory 
into which you are trying to write.  You can get this info with the 
ls -l command.  Example useage:

$ ls -l
total 276
drwxr-xr-x   4 steffen  www          4096 Apr 22  1999 Bookmarks
drwxr-xr-x   2 steffen  www          4096 Jul 27  1999 Development
drwxr-xr-x   2 steffen  www          4096 Jun  9  1999 Netwkg
drwxr-xr-x   2 steffen  www          4096 Apr 12  1999 Personal
drwxr-xr-x   3 steffen  steffen      4096 Mar 17 18:02 SSTRtalk

My web server runs as user www, group www and so can write to the 
first four directories, but not to SSTRtalk.

3) Each person can be a member of many groups.  I like to be a member 
of the group used by the web server.

4) The owner of a directory can change its group and permissions. 
Thus, if I wanted the web server to be able to write to SSTRtalk, I 
would use the following command:

$ chgrp www SSTRtalk

This is all off the top of my head and may contain the occasional 
typo or braino; in any case you probably need to know a little Unix 
to port scripts to a Unix server.  There are oodles of Unix tutorials 
out there, but I am Unix self-taught so cannot recommend a particular 
one.  At Baylor College of Medicine where I have worked they used to 
recommend something called 'Unix for the Impatient', I think.

-David-

p.s. If not a simple permissions problem, it may be that the Unix 
system is set up to not allow CGIs to write to certain directories, 
e.g. any outside the HTML tree.  That is also something you might 
look into.

David Steffen, Ph.D.
President, Biomedical Computing, Inc. <http://www.biomedcomp.com/>
Phone: (713) 610-9770 FAX: (713) 610-9769 E-mail: steffen@biomedcomp.com

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org