×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Script only works through telnet..
2

Script only works through telnet..

Script only works through telnet..

(OP)
I'm having this really odd problem.. I've written a script that works through telnet, but not through a browser. If I run the -c switch through telnet it comes up with 'syntax OK' - and if I run -w I don't get any problems.

But, If I call it through my browser, I get a 'page cannot be displayed' message. Not even an error 500. I've come back to this after nearly 3 months with a clear head, and still can't figure out why..

Basically, the script scans a directory of image files against a flat file database.. if they're in the directory and not in the database it means they're redundant, and should be automatically transferred to a directory called 'remove'. That simple.

It's listed below - I've commented where it stops working in browsers.

Thanks for any help!

Matt.

#!/usr/local/bin/perl

#set content type
print "Content-type:text/html\n\n";

#HTML header
print "<html><head><title>w</title></head><body>Images to remove\n";

#check which products file to use
open (WHO,"data/whichfile.txt");
$whichfile = <WHO>;
close (WHO);

print "$whichfile is current file<br><br>\n";

#open current products file - store in @products
open (INFILE,"data/$whichfile") or dienice("Can't open products file: $!");
@products = <INFILE>;
close (INFILE);
#open images directory - store in @allimages
opendir (IMG, "../public_html/images") or dienice("Can't open image directory: $!");
@allimages = readdir(IMG);
closedir (IMG);
##########################################################
#all ok up to here in browsers - but the rest won't run..#
##########################################################

#for each image file in the directory
foreach $imgfile (@allimages) {
$foundfile=0;
foreach $line (@products) {
chomp($line);
($letsection,$name,$title,$format,$price,$descript,$stockno,$section,$img,$weight,$date,$label,$catno) = split(/\|/,$line);
if ($imgfile eq $img) {
$foundfile = 1;
}
}
if ($foundfile == 0) {
$iftrue="0";
$iftrue = substr($imgfile, 0 , 2);
if ($iftrue eq "fe") {

print "$imgfile<br>\n";
rename ("../public_html/images/$imgfile", "../public_html/remove/$imgfile");
}
}
}

print "</body></html>\n";

RE: Script only works through telnet..

Sorry, I don't have the answer to your question, because I was just about to post exactly the same question myself!!!

My script runs perfectly from the command line in telnet, but will not run when invoked from the "location" bar in a browser. In this case I do get a 500 "internal server error".

All the script does is extract an email address from a text database and sends the same email to all the addresses using sendmail. I print a short "Done" message to the browser with the proper headers etc. when it's through.

Like I say, the entire script works perfectly. All emails come through. I've never run into this before.

Any possiblilities?

Roy

RE: Script only works through telnet..

MathewP,
I suspect that your are asking the web server to do something for which it has insufficient permissions.  The first line of your code looks like UNIX.  I may be preaching to the choir.  If so, sorry.  If not,.....

When you run a piece of code from a command prompt, you are running it as yourself, with all the environmental variables for your environment in force.  Stuff like paths and execute/read/write permissions are all relative to your login.  When you run a piece of code via a browser, it is being run by another, hopefully very weak user, the web daemon.  Your system administrator should have the web daemon setup with very limited abilities for security reasons.  So,

Make sure that the web daemon has sufficient permissions to execute the file you  are trying to run.

Make sure the web daemon can read and/ or write any files that are being used, as appropriate.

Make sure your script is in the 'cgi-bin' directory for the web server ( or a sub dir there in).

If you don't know how to check these things, we can add a little more detail.

You might do a little of what I call 'idiot checking'.  That is not an insult.  I frequently have to check my own idiocy .  You can do an idiot check by making sure you can run a most simple CGI app and then expand it's function step by step to do what you want.

A ridiculously simple cgi app.


#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>A NEW CGI PAGE</TITLE></HEAD>\n";
print "<BODY><P>Here is the text I want to see</P></BODY></HTML>";



'hope this helps.


 
 
 keep the rudder amid ship and beware the odd typo

RE: Script only works through telnet..

I think you have found MatthewP's problem. I would guess the offending line is this one:

rename ("../public_html/images/$imgfile", "../public_html/remove/$imgfile");

unless this directory is chmod 777 (unlikely) the browser is not going to be able to do stuff in these directories.

Unfortunately for me, I can't find the same kind of problem in my own script which follows. It's just too simple a script! the script is also permissioned 755.

#!usr/bin/perl
#### A program to pull email addresses and send a single email

$mailprog = '/usr/sbin/sendmail';
my $fbfile= $path."feedback.txt";    #permissioned 755, a text database
$mailfrom = "me\@mydomain.com";

$message= qq ^
The email message
^;

###### open the file and get email addresses ######################
open (FBFILE,"$fbfile") || die "Content-type: text/html\n\nCan't Open $fbfile(r): $!\n";
my(@LINES)=<FBFILE>;
close(FBFILE);
$SIZE=@LINES;

$prevname="";
$emailcounter=0;
$counter=0;

while ($counter < $SIZE) {
    chomp($LINES[$counter]);
    ( $bidder) = split(/\|/,$LINES[$counter]); #other fields in the database left out
    if ($bidder ne $prevname) {     #skips duplicate entries
        &send_email;
        $emailcounter=$emailcounter+1;
    }
    $prevname = $bidder;
    $counter =$counter+1;
};
 
print "Content-type: text/html\n\n";

print qq ^
<HTML><Body>
Done. $emailcounter separate emails sent.
</Body></HTML>
^;

sub send_email {
#######################################################

# Open The Mail Program
open(MAIL,"|$mailprog -t");

   print MAIL "To: $bidder\n";
   print MAIL "From: $mailfrom\n";
   print MAIL "Subject: We left you feedback!";
    print MAIL "\n\n";
    print MAIL "$message";
close (MAIL);
}

1;

###############

All my other cgi programs in this directory work. They all have the same first line and permissions, and the same sendmail location. I have triple checked the permissioning. there are no syntax or logical errors because it works perfectly from the command line.

RE: Script only works through telnet..

(OP)
Well.. the other 20 scripts in the cgi-bin work fine, so I guess it is as rlingen said - to do with the security permissions on those directories. As it happens global permissions aren't required so I can happily leave it as user only access. And at least I know why now so I'm happy. Thanks to you both!

Matt.



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close