Re: simple Perl CGI scripts help
- From: CAT <yinleew@xxxxxxxxx>
- Date: Tue, 07 Aug 2007 07:12:15 -0700
On Aug 7, 9:42 am, "A. Sinan Unur" <1...@xxxxxxxxxxxxxxxxxxx> wrote:
CAT <yinl...@xxxxxxxxx> wrote in news:1186490295.849914.40820@
57g2000hsv.googlegroups.com:
I wrote a simple perl scripts to run a scripts remotely in another
machine and copy the result back to local server and show it on the
web browser. It will only work on command line (Will show nothing on
browser ) if I defined "APP_ROOT=/opt/APP/server/app" in the remote
scripts.
If I remove this line, it just works fine. (show the result fast on my
IE or Firefox browser)
APP_ROOT is required for me. Then I unset it by put "UnsetEnv
APP_ROOT" in my httpd.conf, however, it still refuses to work.
Your description is confusing and makes it sound like you have a web
server configuration issue. If that is the case, you should post your
question in an appropriate newsgroup. However, your whole description
might be a red herring.
Please help.
root@localbox# cat showremote.cgi
If I understand correctly, you are running this script as root when you
test it from the command line. The web server will be running under a
different user id with different privileges and different (or no) home
directory.
#!/usr/bin/perl
##
## printedi -- CGI program which just prints app check information
##
print "Content-type: text/plain\n\n";
I am not sure if it is a good idea to print headers when there is
nothing to show at the point they are printed.
#This line generates check file
system ("ssh 10.1.1.10 /export/home/admin/check.sh");
And, how is the ssh login to the remote machine authorized? If you are
using keys rather than password authentication, the web server is not
going to have access to the keys you have set up for the root user.
Incidentally, you should bypass the shell and call ssh and scp directly
by using the list form of the system call.
#This line copy the file over to localbox
system ("scp 10.1.1.10:/tmp/check.txt /tmp");
Similarly.
# Name the file
$file1 = '/tmp/check.txt';
A better program would have (untested):
my %config = (
remote_host => '10.1.1.10',
remote_program => '/export/home/admin/check.sh',
remote_file => '/tmp/check.txt',
local_file => '/tmp/check.txt',
);
system ssh => $config{remote_host}, $config{remote_program};
system scp => "$config{remote_host}:$config{remote_file}",
$config{local_file}
You should, of course, check if the system calls succeeded.
print scalar(localtime);
You probably want a newline after this.
open(INFO1, $file1); # Open the file
open my $info1, '<', $config{local_file}
or die "Cannot open '$config{local_file}': $!";
@lines1 = <INFO1>; # Read it into an array
Don't do that. There is no need to slurp the file. You can keep memory
usage independent of file size by doing:
print while <$info1>;
close(INFO1); # Close the file
print @lines1;
system (`/usr/bin/rm /tmp/check.txt`);
perldoc -f unlink
Sinan
--
A. Sinan Unur <1...@xxxxxxxxxxxxxxxxxxx>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
Sinan,
I am using this showme.cgi scripts to run the remote scripts check.sh
on another unix server, the public key already copied over to that
machine so that the password is not required.
My problem is, if I comment this line in the remote scripts, the CGI
will work and will print files to my IE browser
#APP_ROOT=/opt/APP/server/app
#export APP_ROOT
If I leave them uncommented, only the command line will work and the
IE and firefox browser will wait forever even I set up the timeout
value as big enough.
Thanks for your time.
.
- Follow-Ups:
- Re: simple Perl CGI scripts help
- From: Ian Wilson
- Re: simple Perl CGI scripts help
- From: CAT
- Re: simple Perl CGI scripts help
- References:
- simple Perl CGI scripts help
- From: CAT
- Re: simple Perl CGI scripts help
- From: A. Sinan Unur
- simple Perl CGI scripts help
- Prev by Date: Re: simple Perl CGI scripts help
- Next by Date: module OpenOffice::OODoc fails with Unicode characters
- Previous by thread: Re: simple Perl CGI scripts help
- Next by thread: Re: simple Perl CGI scripts help
- Index(es):
Relevant Pages
|