简体   繁体   English

从Perl通过cgi调用时,系统命令未运行

[英]System command not running when called through cgi from Perl

I have been stuck for many days where I have a perl script. 我在Perl脚本中呆了很多天。 I have made a function in my CGI File which has some HTML content and a system command to execute a shell script.Then I have an href which calls the perl file which in turn calls the CGI function and shows the content on the browser. 我在CGI文件中创建了一个函数,该函数具有一些HTML内容和一个用于执行Shell脚本的系统命令。然后我有一个href,该href调用了perl文件,该文件又调用了CGI函数并在浏览器中显示了内容。 But everything is loading except the execution of system command in CGI. 但是,除了在CGI中执行系统命令外,其他所有内容都在加载中。 I tried to put this system command in my Perl File itself and on execution it is successfully executing the shell script from command line. 我试图将此系统命令放入我的Perl文件本身,并且在执行时成功从命令行执行了shell脚本。 But I wanted this to happen on a button click so I had to make a CGI call but still I am not able to call it. 但是我希望在单击按钮时发生这种情况,因此我不得不进行CGI调用,但仍然无法调用它。 I have been through many questions but I still am looking for the perfect answer. 我遇到了很多问题,但我仍在寻找最佳答案。 Here is my code: test1.pl 这是我的代码:test1.pl

#!/usr/bin/perl -w

use strict;

use CGI::Carp qw(fatalsToBrowser);
use Basecamp::UI;
use Basecamp::Dashboard;
use Basecamp::Info;

my $cgi = Basecamp::UI->new->cgi();
my $dashboard = Basecamp::Dashboard->new();
my @html = $cgi->tab_ext();

#push @html, '<div class="page">';
#push @html, newstuff();
#push @html, '</div>';
#print "Hello Hey";
#system( ' sh  /home/basecamplocal/Perforce/depot/qeutils/basecamp_dev/sample.sh ');

print $cgi->begin('Basecamp | ext', $dashboard), $cgi->begin_page();
print @html;
print $cgi->end_page(), $cgi->begin_footer(), $cgi->end_footer(), $cgi->end();

shell script is: shell脚本是:

#!/bin/bash
#perl Basecamp.pl > log_sample.txt
touch log_sample.txt

echo "Good Day"

CGI File Function: CGI文件功能:

=item tab_ext()
======================================================================================

        DESC:   Generates appropriate tabs for About, about.pl.
        OUT:    Returns array of scalars with html to draw the tabs and any associated
                        subtabs.

======================================================================================
=cut
sub tab_ext
{
        my ($self) = @_;
        my $tab = $self->param('tab');
        my @tabs = ('<li><a href="test1.pl?tab=New">Status Restart</a></li>');
        my @subtabs = ();
        my @html = ();

        $tabs[0] = '<li class="selected"><a href="#">Status Restart</a></li>';

        @html = ('<ul id="tabs">', @tabs, '</ul>');

        push @html, ('<ul id="subtabs">', @subtabs, '</ul>');
        print "Content-type: text/html\n\n";
        system("sh /full path to shell file /sample.sh ");


        return @html;

}

and I am calling the test1.pl file on a href call html.The whole html content from CGI is being displayed except the execution of shell script. 我在href调用html上调用了test1.pl文件。除了执行Shell脚本外,CGI的整个html内容都在显示。 A helping hand would be appreciated. 一臂之力将不胜感激。

Looks like you have permission issue. 看来您有权限问题。 First check the permission of your system.sh program and parent directories. 首先检查您的system.sh程序和父目录的权限。 I think web user has no permission to execute the program. 我认为网络用户无权执行该程序。

Test code : test.cgi 测试代码: test.cgi

Persmission : 755 权限:755

#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print header( -type => 'text/html' );
print <<EOF;

<title>Browser Page</title>
<body>
<div> Hellow </div>

EOF

my $command ="sh /tmp/abc.sh";
print "$command<br>";
system($command);
print "</body>";

code: abc.sh 代码: abc.sh

#!/bin/bash

echo "Good Day"

Output on the browser is 浏览器上的输出是

Hellow
sh /tmp/abc.sh 
Good Day

Hope this will help you. 希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM