Can't create file in CGI Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can't create file in CGI Script
# 1  
Old 03-12-2013
Can't create file in CGI Script

Hi I have some simple script within the context of a cgi script that create a file to write to. If I run the script from the command line as root the file is created with no issue. However when I run the script from a web page with the apache account, it dies. The code lines are:

Code:
sub Populate_Session_File       {
        open (NEWOUT,">/var/www/cgi-bin/sessions/$SID") || die "can't open the sessions file";
                print NEWOUT "$SID\011$empnum\011$first_name\011$last_name\011$mailadder\n";
        close (NEWOUT) || die "can't close the spaceout file";
} # end populate session File

And the error I get is:

"[Tue Mar 12 06:07:58 2013] [error] [client IP] can't open the sessions file at /var/www/cgi-bin/riskpect_dsp_login.pl line 238., referer: http://blah.blah
[Tue Mar 12 06:07:58 2013] [error] [client IP] Premature end of script headers: riskpect_dsp_login.pl, referer: http://blah.blah
"

Thanks in advance for any help
# 2  
Old 03-12-2013
httpserver user has to be write priviledge to the destination dir. Something like example:
Code:
# give tmp dir priviledge - everyone can create own file, but only owner can remove it. Compare ex. /var/tmp priviledges
# sticky bit = restricted deletion
chmod 1777 /var/www/cgi-bin/sessions

Or

If ex. www-data is the apache http server user then something
Code:
chown www-data /var/www/cgi-bin/sessions
chmod 755 /var/www/cgi-bin/sessions
# or
chmod 1755 /var/www/cgi-bin/sessions

# 3  
Old 03-12-2013
kshji, I attempted to send you a personal message to thank you. Your advice was most helpful, and I'm back on track!!! For the Record...

YOU CHAMPION!!!

Cheers

If our paths ever cross the drinks are on me!

Larry
# 4  
Old 03-12-2013
When you get an error, I bet PERL has something like C perror() to explicitly say what the error is !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to create spreadsheet in cgi script

hi folks, I am trying to download xlsx from cgi page in browser but not sure where I made a mistake. the cgi script contains the code for creating xlsx and just by clicking on the image I should be able to #!/usr/bin/perl -w use Excel::Writer::XLSX; use DBI; use DBD::mysql; use CGI;... (1 Reply)
Discussion started by: scriptscript
1 Replies

2. Shell Programming and Scripting

Create download button using perl CGI

Hi, I want to insert in a page a .html button that - once it is clicked - opens a save file dialog box by using perl CGI . I know that to create a link to do that I've done : print $cgi->p ( { -class => 'linc' },);I want to do something similar for a download button (0 Replies)
Discussion started by: black_fender
0 Replies

3. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

4. UNIX for Dummies Questions & Answers

create cgi-bin

Hello anyone, I'm a PHP programmer that, through work has to be a server administrator. We have a dedicated server at godaddy. I just found this forum but probably could have asked a thousand questions that I've already figured out. I tried finding anything online and would think this would... (0 Replies)
Discussion started by: Freddythunder
0 Replies

5. Shell Programming and Scripting

Help to create a Return Button using shell script CGI

Hello Guys, I would like to know how can I create a radio button on that its possible to return to the last page, using a ksh CGI shell script. Can someone help ? Thanks so much !!!:b: I tried this, but it is a javascript code ! <INPUT TYPE="button" VALUE="BACK" ... (2 Replies)
Discussion started by: robdcb
2 Replies

6. Shell Programming and Scripting

problem for CGI create Cookie!!!!

Hi Everyone, I am facing the problem to create the cookie in CGI (bash script). Is it possible can create in cgi? or javascript better? Anyone got the sample to create the cookie in cgi(bash script)? Just the login will do ->> USERNAME and PASSWORD after create how to store into the... (2 Replies)
Discussion started by: ryanW
2 Replies

7. Shell Programming and Scripting

create a new directory from cgi script

hello. i hav accepted name of directory from user through a form.now i need to create a directory under cgi-bin of that name.I am not able to do so.n help is required (12 Replies)
Discussion started by: raksha.s
12 Replies

8. Shell Programming and Scripting

calling a cgi file from shell script????

Hi.. Is it possible to call a cgi program which is used to display a pop up message in the else part...On executing the script it directly prints the source code of the pop up screen.. Please if you have any idea,share with us.Thanks. #start success250=`grep -c failure... (1 Reply)
Discussion started by: elavv
1 Replies

9. Shell Programming and Scripting

cgi script to echo a html file

Hi, I'm learning some simple cgi scripting. I can make a script like this, so my browser shows "Hello World" /www/cgi-bin/name.sh --- #!/bin/sh MyName=World echo "<html> Hello $MyName </html>" --- What I'd like is to have a separate html and script files in the cgi folder so ... (1 Reply)
Discussion started by: Performer
1 Replies

10. Shell Programming and Scripting

CGI passing arrays/hashes to another CGI script

If I have a Perl CGI script (script01), which fills an array(s) with information and outputs a HTML page with a link to another CGI page (script02); is there anyway to pass the array(s) from "script01" to "script02" when the page visitor clicks the link? Hope that makes sense! :) (2 Replies)
Discussion started by: WIntellect
2 Replies
Login or Register to Ask a Question