Operating System - Linux
1832961 Members
3569 Online
110048 Solutions
New Discussion

Perl/CGI running external commands

 
SOLVED
Go to solution
Kalin Evtimov
Regular Advisor

Perl/CGI running external commands

Hi!

I am using Perl for extracting and parsing data from my server. I habe a *.cgi, which runs those lines when called:

system ("/usr/bin/perl /opt/webmin-1.230/vimod/load/testreverse.pl");

system ("/usr/local/bin/pl -png /opt/webmin-1.230/vimod/load/$script_name");
---------------------------------------------

The first call doesn't work and I wonder why? The Perl-Script has W,R,X-Rights. If I call it from the shell, there is no problem.

The second is running correctly.
Can anybody help?

Thank you!
9 REPLIES 9
Orhan Biyiklioglu
Respected Contributor

Re: Perl/CGI running external commands

How do you run it from the command line? Are you sure your perl binary is under /usr/bin

Kalin Evtimov
Regular Advisor

Re: Perl/CGI running external commands

I call ot with:

$/dir/script>perl tralala.pl

Perl is in /opt/perl5/bin, but when I changed it it didn't work again.
Zeev Schultz
Honored Contributor

Re: Perl/CGI running external commands

Tried "-w" for perl to see what it complains if at all? I'd also try to separate command and agrument, like "perl" "...".system() does fork I think and calls a shell so it may be some shell thing that doesn't work.See this one also:

http://www.perl.com/doc/FAQs/cgi/idiots-guide.html
So computers don't think yet. At least not chess computers. - Seymour Cray
Daavid Turnbull
Frequent Advisor

Re: Perl/CGI running external commands

Out of curiostiy what is the CGI language are you using? (I am thinking that you might be better off writing the whole think in perl.)

Presuming you have as the first line of your script:

#! /usr/bin/perl

why would you not run:

system("/opt/webmin-1.230/vimod/load/testreverse.pl");

??
Behold the turtle for he makes not progress unless he pokes his head out.
Kalin Evtimov
Regular Advisor

Re: Perl/CGI running external commands

It is perl..
There should not be any difference..anyway I may try this.
Muthukumar_5
Honored Contributor

Re: Perl/CGI running external commands

You have to check with perl binary location. If it is in PATH Variable then you may not need to give full path.

Get perl path as,

$PERL=`which perl`
system("$PERL <script>");

It will work.

~regards

Easy to suggest when don't know about the problem!
Kalin Evtimov
Regular Advisor

Re: Perl/CGI running external commands

Sorry, but it doesn't work. Perl is behaving really strange on this machine. Commeing a line in the source changes the script behaviour completly..It is the system-call in the attachment. The script should create 4 files. There is a system call deleting all old files, before creating the new ones. When this line is not commented, the script creates only one file. If I remove the line, it creats 4 files, as it must be..
All this means, that I don't know where am I stuck- perl programming or system administration :(
Daavid Turnbull
Frequent Advisor
Solution

Re: Perl/CGI running external commands

The system call to remove the files can be done with the unlink() function directly from Perl.

That is tis only system call I can see - Am I missing something?
Behold the turtle for he makes not progress unless he pokes his head out.
Muthukumar_5
Honored Contributor

Re: Perl/CGI running external commands

It is your scripting problem :)

sub create_data_files {

system ("rm -f /opt/webmin-1.230/vimod/load/*.tmp");

}

&create_data_files("hour");
&create_data_files("day");
&create_data_files("week");
&create_data_files("month");

Every execution will delete all .tmp files. It will keep only "month" file only at last. Do you want to delete all old files?

Remove system ("rm -f /opt/webmin-1.230/vimod/load/*.tmp"); from sub create_data_files and put it infront of,

system ("rm -f /opt/webmin-1.230/vimod/load/*.tmp");
&create_data_files("hour");
&create_data_files("day");
&create_data_files("week");
&create_data_files("month");

It will work now. Refer attachment for fresh.

~regards

Easy to suggest when don't know about the problem!