繁体   English   中英

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

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

我在Perl脚本中呆了很多天。 我在CGI文件中创建了一个函数,该函数具有一些HTML内容和一个用于执行Shell脚本的系统命令。然后我有一个href,该href调用了perl文件,该文件又调用了CGI函数并在浏览器中显示了内容。 但是,除了在CGI中执行系统命令外,其他所有内容都在加载中。 我试图将此系统命令放入我的Perl文件本身,并且在执行时成功从命令行执行了shell脚本。 但是我希望在单击按钮时发生这种情况,因此我不得不进行CGI调用,但仍然无法调用它。 我遇到了很多问题,但我仍在寻找最佳答案。 这是我的代码: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脚本是:

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

echo "Good Day"

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;

}

我在href调用html上调用了test1.pl文件。除了执行Shell脚本外,CGI的整个html内容都在显示。 一臂之力将不胜感激。

看来您有权限问题。 首先检查您的system.sh程序和父目录的权限。 我认为网络用户无权执行该程序。

测试代码: test.cgi

权限: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>";

代码: abc.sh

#!/bin/bash

echo "Good Day"

浏览器上的输出是

Hellow
sh /tmp/abc.sh 
Good Day

希望这会帮助你。

暂无
暂无

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

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