[29481] in Perl-Users-Digest
Perl-Users Digest, Issue: 725 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 7 11:10:23 2007
Date: Tue, 7 Aug 2007 08:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 7 Aug 2007 Volume: 11 Number: 725
Today's topics:
Re: Checking user's in passwd file <glex_no-spam@qwest-spam-no.invalid>
Re: copy all files anno4000@radom.zrz.tu-berlin.de
How i convert a excel file to csv file ? <paulito.santana@gmail.com>
Re: How i convert a excel file to csv file ? <serman_d@hotmail.com>
module OpenOffice::OODoc fails with Unicode characters <invalid@invalid.org>
Re: Replacing a line <tadmc@seesig.invalid>
Re: Select / Case in perl <bill@ts1000.us>
Re: Select / Case in perl <noreply@gunnar.cc>
Re: Select / Case in perl <sigzero@gmail.com>
Re: Select / Case in perl <1usa@llenroc.ude.invalid>
simple Perl CGI scripts help <yinleew@gmail.com>
Re: simple Perl CGI scripts help <noreply@gunnar.cc>
Re: simple Perl CGI scripts help <yinleew@gmail.com>
Re: simple Perl CGI scripts help <1usa@llenroc.ude.invalid>
Re: simple Perl CGI scripts help <noreply@gunnar.cc>
Re: simple Perl CGI scripts help <yinleew@gmail.com>
Re: simple Perl CGI scripts help <yinleew@gmail.com>
Re: simple Perl CGI scripts help <yinleew@gmail.com>
Re: simple Perl CGI scripts help <yinleew@gmail.com>
Subroutines and '&' <bill@ts1000.us>
Re: Subroutines and '&' <noreply@gunnar.cc>
Re: Subroutines and '&' <spamtrap@dot-app.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Aug 2007 10:08:33 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Checking user's in passwd file
Message-Id: <46b88af2$0$498$815e3792@news.qwest.net>
Todd Wade wrote:
> On Aug 5, 10:54 am, Fred <itf...@cdw.com> wrote:
>> I have a list of valid users that I need to cross reference to
>> the /etc/passwd files on various systems. So lets suppose the
>> (shortened) list of valid users is:
>>
>> John Doe
>> Susan Archer
>> Monty Python
>>
>> Now let's say there's an entry in the /etc/passwd file for an
>> employee named George Smith who has left the company:
>>
>> gsmith:cXU6Km8JDj:9446:9400:George Smith:/home/gsmith:/bin/bash
>>
>> How would I determine if the George Smith user is invalid?
Invalid or disabled?
>
> I'd DBD::CSV to treat the passwd file as a database table. [...]
Why bother, there are a bunch of functions already available
to deal with the passwd file.
perldoc -f getpwent
perldoc -f setpwent
------------------------------
Date: 7 Aug 2007 10:57:11 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: copy all files
Message-Id: <5hr1g7F3mffjbU1@mid.dfncis.de>
John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> Darius Blaszyk wrote:
> > Thanks Matt, that works! I was having problems with the copy command
> > previously when I tried "/dest_dir/." and "/dest_dir/*.*" and
> > "/dest_dir/*". But it seems I just don't need to add a wildcard after all.
> >
> > One last question, you use "while (</source_dir/*.ext>)" to loop trough
> > the files, is it possible to check for more extensions in the same while
> > loop? I tried
> >
> > while (</source_dir/*.ext>) || (</source_dir/*.txt>)
> >
> > but that doesn't work.
>
> while ( </source_dir/*.{ext,txt}> )
...or
while ( </source_dir/*.ext>, </source_dir/*.txt> )
Anno
------------------------------
Date: Tue, 07 Aug 2007 05:18:50 -0700
From: Santana <paulito.santana@gmail.com>
Subject: How i convert a excel file to csv file ?
Message-Id: <1186489130.651494.156140@22g2000hsm.googlegroups.com>
Hei friends,
i'am new in newbie in Perl, and i need how i convert a excel file in
csv file in linx ?
Can you help me, please ??
Thanks,
Paulito
------------------------------
Date: Tue, 07 Aug 2007 05:46:42 -0700
From: "Serman D." <serman_d@hotmail.com>
Subject: Re: How i convert a excel file to csv file ?
Message-Id: <1186490802.425654.293240@o61g2000hsh.googlegroups.com>
On Aug 7, 2:18 pm, Santana <paulito.sant...@gmail.com> wrote:
> i'am new in newbie in Perl, and i need how i convert a excel file in
> csv file in linx ?
Take a look at the following CPAN modules:
http://search.cpan.org/search?mode=module&query=Spreadsheet%3A%3ARead
http://search.cpan.org/search?mode=module&query=Spreadsheet%3A%3AParseExcel
Apart from this newsgroup, www.perlmonks.org is a good place to search
for perl wisdom:
http://www.perlmonks.org/?node_id=614412
Best of luck
--
Serman D.
------------------------------
Date: Tue, 07 Aug 2007 16:21:51 +0200
From: David Sudlow <invalid@invalid.org>
Subject: module OpenOffice::OODoc fails with Unicode characters
Message-Id: <46b88004$0$27383$ba4acef3@news.orange.fr>
When I try to write out a utf8 string using extendText(),
appendParagraph or other methods with the OpenOffice::OODoc module, I
get the following error:
Cannot decode string with wide characters at C:/Perl/lib/Encode.pm line 162.
I have the localEncoding set to utf8 as I should and it reads in fine
from an office document containing utf8 characters.
Here is a short but complete script that illustrates the issue:
use strict;
use warnings;
use OpenOffice::OODoc;
ooLocalEncoding('utf8');
my $archive = OpenOffice::OODoc::File->new(
"my_document.odt",
create => "text");
my $text = ooDocument(
archive => $archive,
member => 'content'
);
$text->appendParagraph(text => "hello\x{100}");
$archive->save();
------------------------------
Date: Tue, 7 Aug 2007 06:08:21 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Replacing a line
Message-Id: <slrnfbgkl5.5f2.tadmc@tadmc30.sbcglobal.net>
Ved <vedpsingh@gmail.com> wrote:
> It means that "if" condition is not being fuifilled.
> if( m{^//#define \$module_nameFileLoadInput $} )
> ^
> |
> Is something missing at (this place)
Yes, a closing curly bracket.
> i.e. after $module_name in the if condtion ?
You also need an opening curly bracket in the appropriate place.
You also do NOT need (or want) the dollar sign to be backslashed.
> while (my $cpp_file = <$fh>) {
> chop $cpp_file;
You should use chomp() instead of chop() for removing newlines.
> my $module_name = "$cpp_file";
my $module_name = $cpp_file;
See:
perldoc -q vars
What’s wrong with always quoting "$vars"?
> $module_name =~ s/\.cpp$//;#removing trainling .cpp
> print "this is name $module_name\n";
> print "this is CPP $cpp_file\n";
> chomp $module_name;#added
Why did you think that adding that was a good idea?
What did you expect that it would do for you?
(hint: it does nothing for you here.)
> if( m{^//#define \$module_nameFileLoadInput $} )
> #if( s!//(#define ${module_name}FileLoadInput 1)!$1!)
I did not mean that you should put the s/// in the if condition.
I meant that you should use the s/// _instead of_ the if condition.
There is no need to check if it matches first, simply do the s///
and it will do nothing if it does not happen to match.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 07 Aug 2007 03:10:03 -0700
From: Bill H <bill@ts1000.us>
Subject: Re: Select / Case in perl
Message-Id: <1186481403.133787.73030@g4g2000hsf.googlegroups.com>
On Aug 7, 6:08 am, Bill H <b...@ts1000.us> wrote:
> I did a search of the group and found many messages about a select /
> case function in Perl and found references to perldoc -f case and
> perldoc -f switch - but neither of these are found under activestate
> v5.8's perldoc. Can someone point me to some reference on how to
> simulate this structure in perl so I dont have to use endless if's?
>
> Bill H
Never mind - someone must have been reading my mind and posted a FAQ
yesterday about it - not sure why it didnt show up when I searched the
group in google groups though.
Bill H
------------------------------
Date: Tue, 07 Aug 2007 12:09:52 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Select / Case in perl
Message-Id: <5hquu4F3mkj5eU1@mid.individual.net>
Bill H wrote:
> I did a search of the group and found many messages about a select /
> case function in Perl and found references to perldoc -f case and
> perldoc -f switch - but neither of these are found under activestate
> v5.8's perldoc. Can someone point me to some reference on how to
> simulate this structure in perl so I dont have to use endless if's?
perldoc Switch
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 07 Aug 2007 13:57:03 -0000
From: Robert Hicks <sigzero@gmail.com>
Subject: Re: Select / Case in perl
Message-Id: <1186495023.230432.20690@r34g2000hsd.googlegroups.com>
On Aug 7, 6:09 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> Bill H wrote:
> > I did a search of the group and found many messages about a select /
> > case function in Perl and found references to perldoc -f case and
> > perldoc -f switch - but neither of these are found under activestate
> > v5.8's perldoc. Can someone point me to some reference on how to
> > simulate this structure in perl so I dont have to use endless if's?
>
> perldoc Switch
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
I have read under various postings that "Switch" is bad and to not use
it.
Robert
------------------------------
Date: Tue, 07 Aug 2007 14:22:15 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Select / Case in perl
Message-Id: <Xns998569801FAB7asu1cornelledu@127.0.0.1>
Robert Hicks <sigzero@gmail.com> wrote in
news:1186495023.230432.20690@r34g2000hsd.googlegroups.com:
> On Aug 7, 6:09 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
>> Bill H wrote:
>> > I did a search of the group and found many messages about a select
>> > / case function in Perl and found references to perldoc -f case and
>> > perldoc -f switch - but neither of these are found under
>> > activestate v5.8's perldoc. Can someone point me to some reference
>> > on how to simulate this structure in perl so I dont have to use
>> > endless if's?
>>
>> perldoc Switch
>>
>> --
>> Gunnar Hjalmarsson
>> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Please don't quote sigs.
> I have read under various postings that "Switch" is bad and to not use
> it.
I will concur with that. In most cases, using a hash to look up actions
or the plain old cascading if-elsif blocks are quite straightforward.
Switch.pm is a source filter (AFAIK) and therefore can be fooled by
oddities in the layout of the source etc.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Tue, 07 Aug 2007 05:38:15 -0700
From: CAT <yinleew@gmail.com>
Subject: simple Perl CGI scripts help
Message-Id: <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.
Please help.
root@localbox# cat showremote.cgi
#!/usr/bin/perl
##
## printedi -- CGI program which just prints app check information
##
print "Content-type: text/plain\n\n";
#This line generates check file
system ("ssh 10.1.1.10 /export/home/admin/check.sh");
#This line copy the file over to localbox
system ("scp 10.1.1.10:/tmp/check.txt /tmp");
# Name the file
$file1 = '/tmp/check.txt';
print scalar(localtime);
open(INFO1, $file1); # Open the file
@lines1 = <INFO1>; # Read it into an array
close(INFO1); # Close the file
print @lines1;
system (`/usr/bin/rm /tmp/check.txt`);
root@remotebox# cat check.sh
#!/usr/bin/ksh
APP_ROOT=/opt/APP/server/app
export APP_ROOT
TODAY=`date`
echo $TODAY > /tmp/check.txt
echo ""
/opt/APP/server/app /bin/app status | grep NOT-RUNNING >> /tmp/
check.txt
------------------------------
Date: Tue, 07 Aug 2007 14:59:54 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: simple Perl CGI scripts help
Message-Id: <5hr8t0F3ld916U1@mid.individual.net>
CAT wrote:
>
> open(INFO1, $file1); # Open the file
You should check the return value from open.
open INFO1, $file1 or die "Couldn't open $file1: $!";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 07 Aug 2007 06:08:53 -0700
From: CAT <yinleew@gmail.com>
Subject: Re: simple Perl CGI scripts help
Message-Id: <1186492133.181890.109190@57g2000hsv.googlegroups.com>
On Aug 7, 8:59 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> CAT wrote:
>
> > open(INFO1, $file1); # Open the file
>
> You should check the return value from open.
>
> open INFO1, $file1 or die "Couldn't open $file1: $!";
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar,
I do not have any problem with the return value. I can run it with
command line and get my result. However, I follow your suggestion to
add this line in.
My problem is the Environment Variable problem, no doubt.
Thanks
------------------------------
Date: Tue, 07 Aug 2007 13:42:10 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: simple Perl CGI scripts help
Message-Id: <Xns998562B48FD1Aasu1cornelledu@127.0.0.1>
CAT <yinleew@gmail.com> 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 <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Tue, 07 Aug 2007 15:51:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: simple Perl CGI scripts help
Message-Id: <5hrbt0F3lquabU1@mid.individual.net>
CAT wrote:
> On Aug 7, 8:59 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
>> CAT wrote:
>>>
>>> open(INFO1, $file1); # Open the file
>>
>> You should check the return value from open.
>>
>> open INFO1, $file1 or die "Couldn't open $file1: $!";
>
> I do not have any problem with the return value. I can run it with
> command line and get my result. However, I follow your suggestion to
> add this line in.
> My problem is the Environment Variable problem, no doubt.
Don't take anything for granted. Do you know that /tmp/check.txt exists
and is readable by the user the CGI script runs as? If that's not the
case, Perl will tell you if you check the open() return value.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 07 Aug 2007 06:58:53 -0700
From: CAT <yinleew@gmail.com>
Subject: Re: simple Perl CGI scripts help
Message-Id: <1186495133.318862.181960@g4g2000hsf.googlegroups.com>
On Aug 7, 9:42 am, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> CAT <yinl...@gmail.com> 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...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
> clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
Thanks Sinan,
I am not a programmer and sorry for the bad syntax. :)
I ran apache server by user apache and I gave apache user the sudo
priviledge to do almost everything the root could do, it is dangerous,
however it is a test environment and that's fine.
I will follow your suggesting to revise my codes.
However, it is wired that why the web browser could not show my CGI
page after I export the APP_ROOT environment in the remote scripts.
Even I unset it again after the execution of the remote scripts. ( I
do not have any problem to run it on command line, that's the reason I
think it is an Environment Variable problem.)
Thanks again.
------------------------------
Date: Tue, 07 Aug 2007 07:04:09 -0700
From: CAT <yinleew@gmail.com>
Subject: Re: simple Perl CGI scripts help
Message-Id: <1186495449.612262.219970@k79g2000hse.googlegroups.com>
On Aug 7, 9:51 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> CAT wrote:
> > On Aug 7, 8:59 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> >> CAT wrote:
>
> >>> open(INFO1, $file1); # Open the file
>
> >> You should check the return value from open.
>
> >> open INFO1, $file1 or die "Couldn't open $file1: $!";
>
> > I do not have any problem with the return value. I can run it with
> > command line and get my result. However, I follow your suggestion to
> > add this line in.
> > My problem is the Environment Variable problem, no doubt.
>
> Don't take anything for granted. Do you know that /tmp/check.txt exists
> and is readable by the user the CGI script runs as? If that's not the
> case, Perl will tell you if you check the open() return value.
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar,
This file does exist if I did not remove it in the scripts. And, if
there is not the file, apache error_log file will show me the error.
-rw-r--r-- 1 apache other 28 Aug 7 10:02 check.txt
Thanks
------------------------------
Date: Tue, 07 Aug 2007 07:12:15 -0700
From: CAT <yinleew@gmail.com>
Subject: Re: simple Perl CGI scripts help
Message-Id: <1186495935.882426.151050@o61g2000hsh.googlegroups.com>
On Aug 7, 9:42 am, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> CAT <yinl...@gmail.com> 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...@llenroc.ude.invalid>
> (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.
------------------------------
Date: Tue, 07 Aug 2007 07:51:22 -0700
From: CAT <yinleew@gmail.com>
Subject: Re: simple Perl CGI scripts help
Message-Id: <1186498282.657080.292710@g4g2000hsf.googlegroups.com>
I created an html form and want to get the expected result after I
clieck the button, my html file is as following:
bash-2.05$ more ../htdocs/index.html
<FORM METHOD="get"
ACTION="http://127.0.0.1/cgi-bin/newedi.cgi">
<INPUT TYPE=SUBMIT NAME="name"
SIZE=20 VALUE="Show ME">
</FORM>
I could run this scripts without any problem on command line:
bash-2.05$ ./newedi.cgi
APP_ROOT=/APP/source/server/APP #Which is required for my remote
scripts to keep the right ENV parameter.
check.txt 100% |
*****************************************************| 28
00:00
Content-type: text/plain
Tue Aug 7 10:33:02 EDT 2007
bash-2.05$
However, I could not get my file to print to the browser until I
comment these two lines out from the remote scripts which is required:
root@remotebox# cat check.sh
#!/usr/bin/ksh
#APP_ROOT=/opt/APP/server/app
#export APP_ROOT
#############other codes here
I think my problem here is I defined Env variable in the remote site
and I have to unset it locally, right? and how can I do it?
Appreciate for your great help.
------------------------------
Date: Tue, 07 Aug 2007 04:13:25 -0700
From: Bill H <bill@ts1000.us>
Subject: Subroutines and '&'
Message-Id: <1186485205.209362.86930@w3g2000hsg.googlegroups.com>
I have always called my subroutines with an '&', Example:
&something;
sub something
{
return;
}
But I see in the perlfaq that the '&' isnt used. Is there any reason I
should / should't be using the '&' or does it just not make a
difference?
Bill H
------------------------------
Date: Tue, 07 Aug 2007 13:30:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Subroutines and '&'
Message-Id: <5hr3l3F3kpga2U1@mid.individual.net>
Bill H wrote:
> I have always called my subroutines with an '&', Example:
>
> &something;
>
> sub something
> {
> return;
> }
>
> But I see in the perlfaq that the '&' isnt used. Is there any reason I
> should / should't be using the '&' or does it just not make a
> difference?
perldoc -q "&foo"
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 07 Aug 2007 08:27:15 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Subroutines and '&'
Message-Id: <m28x8n34yk.fsf@dot-app.org>
Bill H <bill@ts1000.us> writes:
> I have always called my subroutines with an '&', Example:
>
> &something;
>
> sub something
> {
> return;
> }
>
> But I see in the perlfaq that the '&' isnt used. Is there any reason I
> should / should't be using the '&' or does it just not make a
> difference?
It *does* make a difference - if you don't know or understand what that
difference is, or you don't specifically want the behavior specified by
the &, you shouldn't use it.
You can read about this in "perldoc perlsub".
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 725
**************************************