Re: File write/read problem
On Wednesday, September 24, 2003, at 10:54 PM, [EMAIL PROTECTED] wrote: Now that sounds like that could be the overarching problem. It would also explain (I thingk) why I can't change the permissions of any of those directories with an ftp client. So if I change the ownership of the cgi-bin (and all the folders associated with the server) to www:www, then I should be able to write to the file. How is that accomplished? Thanks for your help, May I suggest that think of the security implications by making cgi-bin work writeable. It only has to be world executeable NOT more. If you want to write to a file write to a directory outside of cgi-bin in mac osx you might want to use /Users/shared/. If you still want change ownership issue the command 'man chown' in the terminal (without the quotes), for changing file permissions use 'man chmod'. Please Do inform yourself before you change ownership and permissions - you can screw yourself big time. JM2C/h
Re: File write/read problem
On Wednesday, September 24, 2003, at 10:44 PM, [EMAIL PROTECTED] wrote: OK, that makes perfect sense, but it is not working here. Here is a basic script which, when run, should create a new file called example.txt because it is not there when the open statement is used. #!/usr/bin/perl print Content-type: text/html\n\n; print Creating new file...; my $newtext = newtext from old; open (USER, example.txt); print USER $newtext; close USER; exit; As you've said, it should create the file in the same directory, in this case the cgi-bin, as the script (which is called write.cgi). I run the call the script from the browser and the script runs fine, except, no file is created. I added a || die ($!) at the file open call and add the CGI::CARP qw(fatalToBowser) at the top and get the following. Permission denied at /Library/WebServer/CGI-Executables/write.cgi All the permissions for each of these directories are 755. Something is a miss. So what can I do?! I'm very confused. Who owns the directories? The Web server runs as user www (unless you're not running the stock httpd). That's probably your problem. HTH, Paul. -- Paul Hoffman :: Taubman Medical Library :: Univ. of Michigan [EMAIL PROTECTED] :: [EMAIL PROTECTED] :: http://www.nkuitse.com/
Re: File write/read problem
On Thursday, September 25, 2003, at 12:33 AM, Greenhalgh David wrote: On Wednesday, Sep 24, 2003, at 20:05 Etc/GMT, Ken Williams wrote: Nope. When you open for reading (), it won't be auto-created. It will when you open for writing or appending ( or ). -Ken Not necessarily on every Mac. The same thing happens to me here, opening a file for writing does not create the file. Well then, you didn't succeed in opening it for writing. =) Try the following code, it will either die or create the files, depending on your permissions: --- #!/usr/bin/perl open FH, foo_write or die Can't create foo_write: $!; print FH some data\n; close FH; open FH, foo_append or die Can't create foo_append: $!; print FH some data\n; close FH; --- There should be no variation of this behavior on any platform perl runs on, '' and '' will always create the file first. -Ken
Re: File write/read problem
In just checked the httpd.conf file and, yes, the user/group is set to www/www. So I need to change it to what? Mark - Original Message - From: Paul Hoffman [EMAIL PROTECTED] To: John Delacour [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, September 25, 2003 5:23 AM Subject: Re: File write/read problem On Wednesday, September 24, 2003, at 10:44 PM, [EMAIL PROTECTED] wrote: OK, that makes perfect sense, but it is not working here. Here is a basic script which, when run, should create a new file called example.txt because it is not there when the open statement is used. #!/usr/bin/perl print Content-type: text/html\n\n; print Creating new file...; my $newtext = newtext from old; open (USER, example.txt); print USER $newtext; close USER; exit; As you've said, it should create the file in the same directory, in this case the cgi-bin, as the script (which is called write.cgi). I run the call the script from the browser and the script runs fine, except, no file is created. I added a || die ($!) at the file open call and add the CGI::CARP qw(fatalToBowser) at the top and get the following. Permission denied at /Library/WebServer/CGI-Executables/write.cgi All the permissions for each of these directories are 755. Something is a miss. So what can I do?! I'm very confused. Who owns the directories? The Web server runs as user www (unless you're not running the stock httpd). That's probably your problem. HTH, Paul. -- Paul Hoffman :: Taubman Medical Library :: Univ. of Michigan [EMAIL PROTECTED] :: [EMAIL PROTECTED] :: http://www.nkuitse.com/
Re: File write/read problem
On Thursday, Sep 25, 2003, at 14:25 Etc/GMT, Ken Williams wrote: On Thursday, September 25, 2003, at 12:33 AM, Greenhalgh David wrote: On Wednesday, Sep 24, 2003, at 20:05 Etc/GMT, Ken Williams wrote: Nope. When you open for reading (), it won't be auto-created. It will when you open for writing or appending ( or ). -Ken Not necessarily on every Mac. The same thing happens to me here, opening a file for writing does not create the file. Well then, you didn't succeed in opening it for writing. =) Try the following code, it will either die or create the files, depending on your permissions: --- #!/usr/bin/perl open FH, foo_write or die Can't create foo_write: $!; print FH some data\n; close FH; open FH, foo_append or die Can't create foo_append: $!; print FH some data\n; close FH; --- There should be no variation of this behavior on any platform perl runs on, '' and '' will always create the file first. -Ken Indeed it ought, and indeed it does on the FreeBSD target host and on my QS, but not on the TiG4. I am sure it is a very obscure permissions thing, though there's never an error in the log file. Mind you, this Powerbook has a record of flakiness so I'm not over-concerned. It's not Perl's fault! Dave
Re: File write/read problem
Mark, Leave the permissions on httpd.conf as they are, in case you're tempted to change them. :-) After you've read this message, I suggest you read up on UNIX permissions -- maybe someone else can recommend a good source of information. The key is that your CGI script runs as user www and group www. All the permissions have to take that into account. I'll describe one way to accomplish what (I think) you want; there may be others. What you need to do is change the owner and/or group of any directories to which your CGI script will be adding files, and of any *existing* files which your CGI script will be modifying. It sounds like you have the following setup: / Library/ WebServer/ CGI-Executables/ write.cgi file1.txt file2.txt ... First, it's not a good idea to create or modify files within the CGI-Executables (a.k.a. cgi-bin) directory, so I would *definitely* put any data files in a separate directory, called (say) CGI-Data: % cd /Library/WebServer % chmod o-w .# make sure permissions on /Library/WebServer are sane % sudo mkdir CGI-Data % ls -l drwxr-xr-x2 root admin 68 Sep 25 11:40 CGI-Data (I'll continue to edit the output of `ls -l' as I've done here.) If there are any existing files to move here, go ahead and move (or copy) them now: % sudo mv file1.txt file2.txt CGI-Data As it stands now, your CGI script won't be able to do anything in this directory or to its files -- you created it as root so, by default, root is its owner. I'm assuming that you want to be able to read and write things in this directory yourself, so what you can do is make yourself the owner and www the group. Let's say by some strange chance your user id is the same as mine, nkuitse: % sudo chown -R nkuitse:www CGI-Data % ls -l drwxr-xr-x 2 nkuitse www 68 Sep 25 12:05 CGI-Data OK, so now you (nkuitse) can do anything you want to do in this folder, and (because of the -R option, which means and do the same to the directory's contents, recursively) you can do anything to the files within it. But your CGI script still can't touch them, because the group permissions are still r-x. That's easy to fix: % chmod -R 775 CGI-Data % ls -l drwxrwxr-x 2 nkuitse www 68 Sep 25 12:05 CGI-Data Note two things: 1. sudo wasn't needed because now you're the owner, and you have write permission (unless you took away write permission from the files you moved, before you moved them) 2. chmod also has an -R option with the same effect as chown's Now all you have to do is modify your script so it writes to ../CGI-Data/file1.txt, etc. instead of just file1.txt, etc. Or you can use absolute paths like /Library/WebServer/CGI-Data/file1.txt if you prefer (this is less portable but that may not matter in your case). If you want to get fancy, you can set up individual subdirectories within CGI-Data, setting the permissions for one so your CGI script can only modify *existing* files, and setting them for the other so your CGI script can modify existing files *and* add files. HTH, Paul. On Thursday, September 25, 2003, at 10:08 AM, Mark Wheeler wrote: In just checked the httpd.conf file and, yes, the user/group is set to www/www. So I need to change it to what? Mark - Original Message - From: Paul Hoffman [EMAIL PROTECTED] To: John Delacour [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, September 25, 2003 5:23 AM Subject: Re: File write/read problem On Wednesday, September 24, 2003, at 10:44 PM, [EMAIL PROTECTED] wrote: OK, that makes perfect sense, but it is not working here. Here is a basic script which, when run, should create a new file called example.txt because it is not there when the open statement is used. #!/usr/bin/perl print Content-type: text/html\n\n; print Creating new file...; my $newtext = newtext from old; open (USER, example.txt); print USER $newtext; close USER; exit; As you've said, it should create the file in the same directory, in this case the cgi-bin, as the script (which is called write.cgi). I run the call the script from the browser and the script runs fine, except, no file is created. I added a || die ($!) at the file open call and add the CGI::CARP qw(fatalToBowser) at the top and get the following. Permission denied at /Library/WebServer/CGI-Executables/write.cgi All the permissions for each of these directories are 755. Something is a miss. So what can I do?! I'm very confused. Who owns the directories? The Web server runs as user www (unless you're not running the stock httpd). That's probably your problem. HTH, Paul. -- Paul Hoffman :: Taubman Medical Library :: Univ. of Michigan [EMAIL PROTECTED] :: [EMAIL PROTECTED] :: http://www.nkuitse.com/ -- Paul Hoffman :: Taubman Medical Library :: Univ. of Michigan [EMAIL PROTECTED] :: [EMAIL PROTECTED] :: http://www.nkuitse.com/
Re: File write/read problem
Well, I gave it a wirl and it works great. I love learning new things! Thanks so much for your help. Does anyone know of a good site for me to learn more about UNIX permissions? Thanks again, Mark - Original Message - From: Paul Hoffman [EMAIL PROTECTED] To: Mark Wheeler [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, September 25, 2003 9:08 AM Subject: Re: File write/read problem Mark, Leave the permissions on httpd.conf as they are, in case you're tempted to change them. :-) After you've read this message, I suggest you read up on UNIX permissions -- maybe someone else can recommend a good source of information. The key is that your CGI script runs as user www and group www. All the permissions have to take that into account. I'll describe one way to accomplish what (I think) you want; there may be others. What you need to do is change the owner and/or group of any directories to which your CGI script will be adding files, and of any *existing* files which your CGI script will be modifying. It sounds like you have the following setup: / Library/ WebServer/ CGI-Executables/ write.cgi file1.txt file2.txt ... First, it's not a good idea to create or modify files within the CGI-Executables (a.k.a. cgi-bin) directory, so I would *definitely* put any data files in a separate directory, called (say) CGI-Data: % cd /Library/WebServer % chmod o-w .# make sure permissions on /Library/WebServer are sane % sudo mkdir CGI-Data % ls -l drwxr-xr-x2 root admin 68 Sep 25 11:40 CGI-Data (I'll continue to edit the output of `ls -l' as I've done here.) If there are any existing files to move here, go ahead and move (or copy) them now: % sudo mv file1.txt file2.txt CGI-Data As it stands now, your CGI script won't be able to do anything in this directory or to its files -- you created it as root so, by default, root is its owner. I'm assuming that you want to be able to read and write things in this directory yourself, so what you can do is make yourself the owner and www the group. Let's say by some strange chance your user id is the same as mine, nkuitse: % sudo chown -R nkuitse:www CGI-Data % ls -l drwxr-xr-x 2 nkuitse www 68 Sep 25 12:05 CGI-Data OK, so now you (nkuitse) can do anything you want to do in this folder, and (because of the -R option, which means and do the same to the directory's contents, recursively) you can do anything to the files within it. But your CGI script still can't touch them, because the group permissions are still r-x. That's easy to fix: % chmod -R 775 CGI-Data % ls -l drwxrwxr-x 2 nkuitse www 68 Sep 25 12:05 CGI-Data Note two things: 1. sudo wasn't needed because now you're the owner, and you have write permission (unless you took away write permission from the files you moved, before you moved them) 2. chmod also has an -R option with the same effect as chown's Now all you have to do is modify your script so it writes to ../CGI-Data/file1.txt, etc. instead of just file1.txt, etc. Or you can use absolute paths like /Library/WebServer/CGI-Data/file1.txt if you prefer (this is less portable but that may not matter in your case). If you want to get fancy, you can set up individual subdirectories within CGI-Data, setting the permissions for one so your CGI script can only modify *existing* files, and setting them for the other so your CGI script can modify existing files *and* add files. HTH, Paul. On Thursday, September 25, 2003, at 10:08 AM, Mark Wheeler wrote: In just checked the httpd.conf file and, yes, the user/group is set to www/www. So I need to change it to what? Mark - Original Message - From: Paul Hoffman [EMAIL PROTECTED] To: John Delacour [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, September 25, 2003 5:23 AM Subject: Re: File write/read problem On Wednesday, September 24, 2003, at 10:44 PM, [EMAIL PROTECTED] wrote: OK, that makes perfect sense, but it is not working here. Here is a basic script which, when run, should create a new file called example.txt because it is not there when the open statement is used. #!/usr/bin/perl print Content-type: text/html\n\n; print Creating new file...; my $newtext = newtext from old; open (USER, example.txt); print USER $newtext; close USER; exit; As you've said, it should create the file in the same directory, in this case the cgi-bin, as the script (which is called write.cgi). I run the call the script from the browser and the script runs fine, except, no file is created. I added a || die ($!) at the file open call and add the CGI::CARP qw(fatalToBowser) at the top and get the following. Permission denied at /Library/WebServer/CGI-Executables/write.cgi
File write/read problem
Hi, This is my first post to this group. Please forgive me if this is the wrong group for this question. I've been coding for a short time (a year or so) and love it. I've been using other hosts for my scripts, and am now setting up my OSX server. I've run into a snag. I can't figure it out. When I try to read (or write, for that matter) to a file nothing happens. Below is an example script. If the file is there, nothing. If the files is not there, nothing. I get the initial print statement about the file contents, but that's it. Is this a permissions problem? I've checked the permissions of the folder and it's 775, everything looks good. What am I missing. Again, forgive me if this post is misplaced. Mark -- #!/usr/bin/perl -w use strict; print Content-type: text/html\n\n; print The contents of the file: brbr; open (DATA, example.txt) || die (Could not open file br $!); my @text = DATA; print @text; close (DATA); exit; ---
Re: File write/read problem
On 9/24/03 6:37 AM, Mark Wheeler [EMAIL PROTECTED] wrote: Hi, This is my first post to this group. Please forgive me if this is the wrong group for this question. I've been coding for a short time (a year or so) and love it. I've been using other hosts for my scripts, and am now setting up my OSX server. I've run into a snag. I can't figure it out. When I try to read (or write, for that matter) to a file nothing happens. Below is an example script. If the file is there, nothing. If the files is not there, nothing. I get the initial print statement about the file contents, but that's it. Is this a permissions problem? I've checked the permissions of the folder and it's 775, everything looks good. What am I missing. Again, forgive me if this post is misplaced. Mark -- #!/usr/bin/perl -w use strict; print Content-type: text/html\n\n; print The contents of the file: brbr; open (DATA, example.txt) || die (Could not open file br $!); my @text = DATA; print @text; close (DATA); exit; --- The above runs for me just fine (perl 5.8.0/ 10.2.8) from within bbedit. Since you get the initial statement - e.g. Part of your program are actually run through the interpreter I assume that you've taken care of the path to perl and also made sure you got Unix and NOT Mac line breaks. You probably intend to run this as a cgi script - thus how did you actually run the script? /h
Re: File write/read problem
Yes, I am running this as a cgi. I called it from a web browser. IE 6 on a PC. Yes, the script has no Mac line endings. I wrote it on a PC using a text editor. I've done nothing different than I have for all my other scripts. I just don't understand. Here is the path: tonedeaf.redirectme.net/cgi-bin/write.cgi The script is in the /Library/WebServer/CGI-Executables/ folder. I can get other scripts to run fine, but just can't read or write files. Any ideas you may have would be greatly appreciated. Thanks, Mark - Original Message - From: Hannes [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: Mark Wheeler [EMAIL PROTECTED] Sent: Wednesday, September 24, 2003 8:35 AM Subject: Re: File write/read problem On 9/24/03 6:37 AM, Mark Wheeler [EMAIL PROTECTED] wrote: Hi, This is my first post to this group. Please forgive me if this is the wrong group for this question. I've been coding for a short time (a year or so) and love it. I've been using other hosts for my scripts, and am now setting up my OSX server. I've run into a snag. I can't figure it out. When I try to read (or write, for that matter) to a file nothing happens. Below is an example script. If the file is there, nothing. If the files is not there, nothing. I get the initial print statement about the file contents, but that's it. Is this a permissions problem? I've checked the permissions of the folder and it's 775, everything looks good. What am I missing. Again, forgive me if this post is misplaced. Mark -- #!/usr/bin/perl -w use strict; print Content-type: text/html\n\n; print The contents of the file: brbr; open (DATA, example.txt) || die (Could not open file br $!); my @text = DATA; print @text; close (DATA); exit; --- The above runs for me just fine (perl 5.8.0/ 10.2.8) from within bbedit. Since you get the initial statement - e.g. Part of your program are actually run through the interpreter I assume that you've taken care of the path to perl and also made sure you got Unix and NOT Mac line breaks. You probably intend to run this as a cgi script - thus how did you actually run the script? /h
Re: File write/read problem
At 06:37 -0700 9/24/03, Mark Wheeler wrote: #!/usr/bin/perl -w use strict; print Content-type: text/html\n\n; print The contents of the file: brbr; open (DATA, example.txt) || die (Could not open file br $!); my @text = DATA; print @text; close (DATA); exit; If you're calling the script from Apache or another CGI you will not see the die message. Also, from Apache the execute bit will need to be set: chmod 775 thescript.pl How about? if (! open (DATA, example.txt) { print P Could not open file, $!\n; die; } -- -- There are 10 kinds of people: those who understand binary, and those who don't --
Re: File write/read problem
That's a good idea, but I'm not at that location, and my remote login is turned off, right now. I can try it when I get there later today. Presuming it IS a CGI problem, what would I need to check? And opposite of that, what would I need to check? Thanks again, Mark - Original Message - From: Hannes [EMAIL PROTECTED] To: Mark Wheeler [EMAIL PROTECTED] Sent: Wednesday, September 24, 2003 9:09 AM Subject: Re: File write/read problem On 9/24/03 7:57 AM, Mark Wheeler [EMAIL PROTECTED] wrote: Yes, I am running this as a cgi. I called it from a web browser. IE 6 on a PC. Yes, the script has no Mac line endings. I wrote it on a PC using a text editor. I've done nothing different than I have for all my other scripts. I just don't understand. Here is the path: tonedeaf.redirectme.net/cgi-bin/write.cgi The script is in the /Library/WebServer/CGI-Executables/ folder. I can get other scripts to run fine, but just can't read or write files. Any ideas you may have would be greatly appreciated. Thanks, Just to see if it is a cgi problem, have you tried running it on the commandline with: /usr/bin/perl example.txt from the directory where example.txt is located? Cheers/h
Re: File write/read problem
In the example.txt, that was created by the same text editor that created the script. As well, if I change the script to write to example.txt file (or any file), and there is no file there to write to, it should create a file, but it does not. I'll add the CGI::carp... and see what info I can glean from there. Thanks, Mark - Original Message - From: Adam Witney [EMAIL PROTECTED] To: Mark Wheeler [EMAIL PROTECTED] Sent: Wednesday, September 24, 2003 10:14 AM Subject: Re: File write/read problem Ah, good point! :-) although it may still be suffering line endings problems in the example.txt file. Best thing would be to try what someone else suggested and get the errors onto the web page.. As was mentioned die errors do not show up. I used to add this line use CGI::Carp qw(fatalsToBrowser); to the top of the script, and this would send more errors to the browser... (although I haven't tried it in a while and may not have all the syntax correct) Adam Thanks for the link. It makes sense, but if there were line ending problems, wouldn't they be throughout the entire script, and thus the script wouldn't work at all? The script is running (no errors), it just can't read (or write) files. Mark - Original Message - From: Adam Witney [EMAIL PROTECTED] To: Mark Wheeler [EMAIL PROTECTED] Sent: Wednesday, September 24, 2003 9:48 AM Subject: Re: File write/read problem This is a common problem when taking files from a PC onto the mac... You can usually tell if they are the wrong line endings by opening up a terminal and just displaying the file using more perl.pl ... In the relevant directory I always use BBEdit to convert them... But you can add a line to your perl code to take care of it I think... can't remember what at the moment though!! This may help though... http://bumppo.net/lists/macperl/1997/09/msg00039.html Remember to check example.txt as well for the correct endings Adam Well, I've been using this editor for about a year, now, and have not had a problem with line-endings on my other hosts before. What should I look for to check the line-endings? Mark - Original Message - From: Adam Witney [EMAIL PROTECTED] To: Mark Wheeler [EMAIL PROTECTED] Sent: Wednesday, September 24, 2003 9:26 AM Subject: Re: File write/read problem But if you wrote it on a PC then it probably has PC line endings, not unix. You will probably need to convert them first to unix line endings. Yes, I am running this as a cgi. I called it from a web browser. IE 6 on a PC. Yes, the script has no Mac line endings. I wrote it on a PC using a text editor. I've done nothing different than I have for all my other scripts. I just don't understand. Here is the path: tonedeaf.redirectme.net/cgi-bin/write.cgi The script is in the /Library/WebServer/CGI-Executables/ folder. I can get other scripts to run fine, but just can't read or write files. Any ideas you may have would be greatly appreciated. Thanks, Mark - Original Message - From: Hannes [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: Mark Wheeler [EMAIL PROTECTED] Sent: Wednesday, September 24, 2003 8:35 AM Subject: Re: File write/read problem On 9/24/03 6:37 AM, Mark Wheeler [EMAIL PROTECTED] wrote: Hi, This is my first post to this group. Please forgive me if this is the wrong group for this question. I've been coding for a short time (a year or so) and love it. I've been using other hosts for my scripts, and am now setting up my OSX server. I've run into a snag. I can't figure it out. When I try to read (or write, for that matter) to a file nothing happens. Below is an example script. If the file is there, nothing. If the files is not there, nothing. I get the initial print statement about the file contents, but that's it. Is this a permissions problem? I've checked the permissions of the folder and it's 775, everything looks good. What am I missing. Again, forgive me if this post is misplaced. Mark -- #!/usr/bin/perl -w use strict; print Content-type: text/html\n\n; print The contents of the file: brbr; open (DATA, example.txt) || die (Could not open file br $!); my @text = DATA; print @text; close (DATA); exit; --- The above runs for me just fine (perl 5.8.0/ 10.2.8) from within bbedit. Since you get the initial statement - e.g. Part of your program are actually run through the interpreter I assume that you've taken care of the path to perl and also made sure you got Unix and NOT Mac line breaks. You probably intend to run this as a cgi script - thus how did you actually run the script? /h -- This message has been scanned for viruses and dangerous content by MailScanner
Re: File write/read problem
At 07:57 -0700 9/24/03, Mark Wheeler wrote: Yes, I am running this as a cgi. I called it from a web browser. IE 6 on a PC. Yes, the script has no Mac line endings. I wrote it on a PC using a text editor. Peecee's use a CR/LF pair for line ends. If you uploaded it in ASCII mode with ftp it should get converted to the ends in use on the server. But modern ftp clients aren't very good at that. Extra CR characters seen in the lines might cause problems with the OS neXt server which will - I'm reasonably sure - want simple LF ends. -- -- There are 10 kinds of people: those who understand binary, and those who don't --
Re: File write/read problem
OK, here's the latest. I put in the CGI::CARP...and got my errors to the screen. On both the read and write to the file (example.txt) if the file exists and the permissions are sett correctly, for example.txt, everything works great. BUT two things I noticed: 1. When I ftp a file to the cgi-bin, for the first time, the permission setting are automatically set to 640, not 644 which is what I am used to, so I didn't check that till just now. Obviously, when changed to 644, the read and writing process works. 2. And here's the rub for the whole deal, I think (and my lack of programming skill). When I try to open the file, and it doesn't exist, I get the error of can't open a file it can't find. BUT I was under the impression that when I used the or or in an open command i.e.: open (DATA, example.txt); that it would creat the file if it wasn't there (with the appropriate [default?] permissions...at least that's what happens on my other hosts. And if that is true, is there a place in the httpd.conf file to set the default permissions for newly created files/folders, as well as allowing new files to be created if not found? Why is it that on my other host (Hostcentric.com) that files are created when not found but on my Mac (10.2.6) they are not? Any ideas, anyone. As always, thanks for the help. Mark
Re: File write/read problem
At 7:57 am -0700 24/9/03, Mark Wheeler wrote: Yes, I am running this as a cgi. I called it from a web browser. IE 6 on a PC. Yes, the script has no Mac line endings. I wrote it on a PC using a text editor. I've done nothing different than I have for all my other scripts. I just don't understand. Here is the path: tonedeaf.redirectme.net/cgi-bin/write.cgi The script is in the /Library/WebServer/CGI-Executables/ folder. I can get other scripts to run fine, but just can't read or write files. Any ideas you may have would be greatly appreciated. You simply don't have permission to write to the file. Compare these two: http://cgi.bd8.com/cgi-bin/hello.pl #!/usr/bin/perl $f = test.txt ; $error = no error ; $command = open F, \$f\ or \$error and close F; open F, $f or $error = $! and close F ; print EOT ; Content-Type: text/html h1$command/h1 h1--gt; $error/h1 EOT # http://cgi.bd8.com/cgi-bin/hello2.pl #!/usr/bin/perl $f = test.txt ; $error = no error ; $command = open F, \$f\ or \$error = \$! and close F; open F, $f or $error = $! and close F ; $s = F; print EOT ; Content-Type: text/html h1$command/h1 h1--gt; $error. File Contents: $s/h1 EOT #
Re: File write/read problem
At 11:54 am -0700 24/9/03, Mark Wheeler wrote: .. I was under the impression that when I used the or or in an open command i.e.: open (DATA, example.txt); that it would creat the file if it wasn't there (with the appropriate [default?] permissions...at least that's what happens on my other hosts. And if that is true, is there a place in the httpd.conf file to set the default permissions for newly created files/folders, as well as allowing new files to be created if not found? Why is it that on my other host (Hostcentric.com) that files are created when not found but on my Mac (10.2.6) they are not? Any ideas, anyone. For example: http://cgi.bd8.com/cgi-bin/showdate.pl has the script: #!/usr/bin/perl $f = textfiles/date.txt ; open F, $f ; print F scalar localtime; open F, $f ; $s = F; print Content-Type: text/html\n\nh1$s/h1 ; showdate.pl has permissions 755 texfiles/ has permissions 777 date.txtis created by showdate.pl with permissions 644
Re: File write/read problem
OK, that makes perfect sense, but it is not working here. Here is a basic script which, when run, should create a new file called example.txt because it is not there when the open statement is used. #!/usr/bin/perl print Content-type: text/html\n\n; print Creating new file...; my $newtext = newtext from old; open (USER, example.txt); print USER $newtext; close USER; exit; As you've said, it should create the file in the same directory, in this case the cgi-bin, as the script (which is called write.cgi). I run the call the script from the browser and the script runs fine, except, no file is created. I added a || die ($!) at the file open call and add the CGI::CARP qw(fatalToBowser) at the top and get the following. Permission denied at /Library/WebServer/CGI-Executables/write.cgi All the permissions for each of these directories are 755. Something is a miss. So what can I do?! I'm very confused. Mark --- On Wednesday, September 24, 2003, at 03:02 PM, John Delacour wrote: At 11:54 am -0700 24/9/03, Mark Wheeler wrote: .. I was under the impression that when I used the or or in an open command i.e.: open (DATA, example.txt); that it would creat the file if it wasn't there (with the appropriate [default?] permissions...at least that's what happens on my other hosts. And if that is true, is there a place in the httpd.conf file to set the default permissions for newly created files/folders, as well as allowing new files to be created if not found? Why is it that on my other host (Hostcentric.com) that files are created when not found but on my Mac (10.2.6) they are not? Any ideas, anyone. For example: http://cgi.bd8.com/cgi-bin/showdate.pl has the script: #!/usr/bin/perl $f = textfiles/date.txt ; open F, $f ; print F scalar localtime; open F, $f ; $s = F; print Content-Type: text/html\n\nh1$s/h1 ; showdate.pl has permissions 755 texfiles/ has permissions 777 date.txtis created by showdate.pl with permissions 644
Re: File write/read problem
Hi Mark, you wrote... Permission denied at /Library/WebServer/CGI-Executables/write.cgi All the permissions for each of these directories are 755. Something is a miss. So what can I do?! I'm very confused. There's your problem. 755 will not allow the www user (or whatever you've set apache to run as) to write into that directory. The permission for all is read and execute, *not* write. Hence permission denied. Try getting it to write to some junk directory on which you've set permissions to be 777 (say). Success will come! Cheers, Paul
Re: File write/read problem
Ok, I'll make a new directory inside the cgi-bin, and set it to 777, and try to write to that. A side note, though. I should be able to write directly to the cgi-bin, though, right? I tried to set the cgi-bin directory to 777, and was not able to. I received an error, so something else is not allowing me to change anything. Just a thought. I'll let you know how writing to a new directory helps. Mark Hi Mark, you wrote... Permission denied at /Library/WebServer/CGI-Executables/write.cgi All the permissions for each of these directories are 755. Something is a miss. So what can I do?! I'm very confused. There's your problem. 755 will not allow the www user (or whatever you've set apache to run as) to write into that directory. The permission for all is read and execute, *not* write. Hence permission denied. Try getting it to write to some junk directory on which you've set permissions to be 777 (say). Success will come! Cheers, Paul
Re: File write/read problem
Now that sounds like that could be the overarching problem. It would also explain (I thingk) why I can't change the permissions of any of those directories with an ftp client. So if I change the ownership of the cgi-bin (and all the folders associated with the server) to www:www, then I should be able to write to the file. How is that accomplished? Thanks for your help, Mark As you've said, it should create the file in the same directory, in this case the cgi-bin, as the script (which is called write.cgi). I run the call the script from the browser and the script runs fine, except, no file is created. I added a || die ($!) at the file open call and add the CGI::CARP qw(fatalToBowser) at the top and get the following. Permission denied at /Library/WebServer/CGI-Executables/write.cgi All the permissions for each of these directories are 755. Something is a miss. So what can I do?! I'm very confused. But owned by whom? By default the directory is owned by root:admin. With apache running as www:www it won't be able to write to that directory unless you either change ownership or open the directory wide with 777. -Charles Albrecht [EMAIL PROTECTED]