By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,842 Members | 1,426 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,842 IT Pros & Developers. It's quick & easy.

Problem in CGI script

P: 5
hi,

I am trying to create a web application where i have a form to upload a file,which is then processed by a cgi script and gives me out the output,
here is the code which i use,

Expand|Select|Wrap|Line Numbers
  1. # Configuration
  2. my $EXECUTABLE_DIRECTORY = "/web_server/Test";
  3. my $CREATE_DIRECTORY = "//web_server/Output";
  4.  
  5.  
  6. my $cgi = CGI->new();
  7. my $pdb_file = $cgi->param("upfile");
  8. $pdb_file =~ s/.*[\/\\](.*)/$1/; 
  9. die "Missing PDB file \n" if(!$pdb_file);
  10. print STDERR "PDB file is $pdb_file\n";
  11. my $mode = 'SH';                    
  12.  
  13. my $read_file = $cgi->upload("upfile"); 
  14.  open (UPFILE,">$CREATE_DIRECTORY/$pdb_file"); 
  15.  while ( <$pdb_file> )  { 
  16.    print UPFILE; 
  17.    print ;
  18.  } 
  19.  close UPFILE; 
  20.  
  21.  
  22. if ($mode eq 'SH'){
  23.     system "$EXECUTABLE_DIRECTORY/pdb2alm $CREATE_DIRECTORY/$pdb_file > $CREATE_DIRECTORY/query.alm";
  24.     system "$EXECUTABLE_DIRECTORY/command_arg_alm_exp $CREATE_DIRECTORY/query.alm > $CREATE_DIRECTORY/distances_SH.log" ;
  25.     open(IN,"<$CREATE_DIRECTORY/distances_SH.log");
  26.     my $line;
  27.     my %lig_name;
  28.     while($line=<IN>){
  29.         chomp $line;
  30.         my @words = split(' ', $line);
  31.         $lig_name{$words[1]} = $words[0];
  32.         }
  33.     close IN;
  34.     my $count=1;
  35.     foreach my $key (sort { $lig_name{$a} <=> $lig_name{$b} }keys %lig_name){
  36.         open(FILE,"</Users/gunasekp/SH/ligand/ligand_$key.pdb");
  37.         if($count<=10){
  38.             while(<FILE>){
  39.             if($_ =~ /(COMPND)\s+(\w+)\s+(.*)/){
  40.                 print "$count    ",$3,"     ",$lig_name{$key},"\n";
  41.                 }
  42.             }
  43.         }
  44.         $count++;
  45.     }
  46.     ......code continues
  47.  
the problem is when i see the error log it says the

" malformed header from script. Bad header=COMPND Y 2p-DEOXY-N6-(S)STYR: /Users/gunasekp/Sites/cgi-bin/automate_cgi.pl
sh: line 1: /Users/gunasekp/web_server/Output/query.alm: Permission denied
sh: line 1: /Users/gunasekp/web_server/Output/distances_SH.log: Permission denied "

2)(pdb2alm and command_....) are executable c++ files which are placed in a directory in harddisk and whose configuration is (drwxr-xr-x and for files -rwxrwxrwx)
3) the output files like query.alm are written to directory whose configuration is (drwxrwxrwx and for files -rw-r--r--)

help me to solve this problems?

Prasad.
Jan 7 '08 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
hi,

I am trying to create a web application where i have a form to upload a file,which is then processed by a cgi script and gives me out the output,
here is the code which i use,

Expand|Select|Wrap|Line Numbers
  1. # Configuration
  2. my $EXECUTABLE_DIRECTORY = "/web_server/Test";
  3. my $CREATE_DIRECTORY = "//web_server/Output";
  4.  
  5.  
  6. my $cgi = CGI->new();
  7. my $pdb_file = $cgi->param("upfile");
  8. $pdb_file =~ s/.*[\/\\](.*)/$1/; 
  9. die "Missing PDB file \n" if(!$pdb_file);
  10. print STDERR "PDB file is $pdb_file\n";
  11. my $mode = 'SH';                    
  12.  
  13. my $read_file = $cgi->upload("upfile"); 
  14.  open (UPFILE,">$CREATE_DIRECTORY/$pdb_file"); 
  15.  while ( <$pdb_file> )  { 
  16.    print UPFILE; 
  17.    print ;
  18.  } 
  19.  close UPFILE; 
  20.  
  21.  
  22. if ($mode eq 'SH'){
  23.     system "$EXECUTABLE_DIRECTORY/pdb2alm $CREATE_DIRECTORY/$pdb_file > $CREATE_DIRECTORY/query.alm";
  24.     system "$EXECUTABLE_DIRECTORY/command_arg_alm_exp $CREATE_DIRECTORY/query.alm > $CREATE_DIRECTORY/distances_SH.log" ;
  25.     open(IN,"<$CREATE_DIRECTORY/distances_SH.log");
  26.     my $line;
  27.     my %lig_name;
  28.     while($line=<IN>){
  29.         chomp $line;
  30.         my @words = split(' ', $line);
  31.         $lig_name{$words[1]} = $words[0];
  32.         }
  33.     close IN;
  34.     my $count=1;
  35.     foreach my $key (sort { $lig_name{$a} <=> $lig_name{$b} }keys %lig_name){
  36.         open(FILE,"</Users/gunasekp/SH/ligand/ligand_$key.pdb");
  37.         if($count<=10){
  38.             while(<FILE>){
  39.             if($_ =~ /(COMPND)\s+(\w+)\s+(.*)/){
  40.                 print "$count    ",$3,"     ",$lig_name{$key},"\n";
  41.                 }
  42.             }
  43.         }
  44.         $count++;
  45.     }
  46.     ......code continues
  47.  
the problem is when i see the error log it says the

" malformed header from script. Bad header=COMPND Y 2p-DEOXY-N6-(S)STYR: /Users/gunasekp/Sites/cgi-bin/automate_cgi.pl
sh: line 1: /Users/gunasekp/web_server/Output/query.alm: Permission denied
sh: line 1: /Users/gunasekp/web_server/Output/distances_SH.log: Permission denied "

2)(pdb2alm and command_....) are executable c++ files which are placed in a directory in harddisk and whose configuration is (drwxr-xr-x and for files -rwxrwxrwx)
3) the output files like query.alm are written to directory whose configuration is (drwxrwxrwx and for files -rw-r--r--)

help me to solve this problems?

Prasad.
The first thing that you need to do is put the pragmas "use strict" and "use warnings" at the beginning of your script. This will ensure that all is right with syntax and such.

Next, if you look at this line:

Expand|Select|Wrap|Line Numbers
  1. my $CREATE_DIRECTORY = "//web_server/Output";
  2.  
Why is the begining of this double slashed? In the variable before this one, it is single slashed. I can only assume you are working on Unix, and if you are, this should be single slashed.

Regards,

Jeff
Jan 7 '08 #2

P: 5
that is a typo while copy and paste,
in my code i have only single slash anda ll the pragmas are at the top.,thats a bit of code not the full one.
Jan 7 '08 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
that is a typo while copy and paste,
in my code i have only single slash anda ll the pragmas are at the top.,thats a bit of code not the full one.
Ok, if that is the case, then I would check all of my permissions, especially on the output directory as you are clearly getting "Permission Denied" errors. Check to ensure that you can create files in that directory as whatever user you are executing as.

Regards,

Jeff
Jan 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.