我正在尝试使用以下 perl 驱动程序执行带有参数的 php 脚本:
#!/opt/local/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Cwd;
my %args = ();
GetOptions(
\%args, "NUM_AGENTS|a=s",
"HOST_NAME|h=s", "TIME_STAGGER|t=s",
"USER_NAME|un=s", "USER_PASS|pw=s",
"TARGET_PAGE|p=s"
) or die "Unknown parameter!\n";
my $i = 0;
my $startTime = time;
my $pwd = getcwd();
my $logdir = "$pwd/load-logs";
mkdir $logdir
or die "Cannot mkdir $logdir: $!"
unless -d $logdir;
chmod 0755, $logdir or die "Cannot chmod 0755 $logdir: $!";
my $startTimeTemp = $args{NUM_AGENTS} + $startTime;
my $startTime2 = $startTimeTemp + 10;
mkdir( "$logdir/$startTime2", 0777 )
or die "Cannot mkdir $logdir/$startTime2: $!"
unless -d "$logdir/$startTime2";
my $random_number = rand() * 10;
my $execDelay =
( $random_number % $args{TIME_STAGGER} ) * ( ( $random_number % 100 ) );
my $procStartTime = $startTime2 + $execDelay;
my $reqlogfile = "$logdir/$startTime2/req.log";
my $resplogfile = "$logdir/$startTime2/resp.log";
print "NUM_AGENTS: " . "$args{NUM_AGENTS}\n";
print "HOST_NAME: " . "$args{HOST_NAME}\n";
print "procStartTime: " . "$procStartTime\n";
print "i: " . "$i\n";
print "TARGET_PAGE: " . "$args{TARGET_PAGE}\n";
print "resplogfile: " . "$resplogfile\n";
print "USER_NAME: " . "$args{USER_NAME}\n";
print "USER_PASS: " . "$args{USER_PASS}\n";
print "execDelay: " . "$execDelay\n";
print "COMMON_SID: " . "$args{COMMON_SID}\n";
while ( $args{NUM_AGENTS} > $i ) {
$i++;
print "count: " . "$i\n";
my $argString =
"'$args{NUM_AGENTS}' '$args{HOST_NAME}' '$procStartTime' '$i' '$args{TARGET_PAGE}' 'resplogfile' '$reqlogfile' '$args{USER_NAME}' '$args{USER_PASS}' '$execDelay' '$args{COMMON_SID}'";
system("php loadAgent_curl.php $argString") == 0 or die "failed to execute: $!";
sleep 1;
#system("ls");
}
但似乎有问题:
system("php loadAgent_curl.php $argString")
由于 ls 系统命令运行良好,但带参数的 php 命令却没有
此 perl 脚本的命令行参数可以是:
-a 10 -h ktest.test.net -t 5 -un admin -pw adminpassword -p "acViewer/index.html?StartDate=20090926040000&EndDate=20111220235959"