我必须调用一个接受参数的PHP脚本。。
php /home/flintarm/www/store/magmi-importer/cli/magmi.cli.php -profile=Category -mode=create -logger=CLILogger
如果我使用PuTTY登录并进行交互式登录,这非常好。
我正在尝试从SSIS加载项任务中调用此命令行。(COZYROC SSH执行任务,实际上无所谓),这似乎是非交互工作的。
当它运行时
php
好,但忽略参数(因此不好)
以下是PHP源代码。。
<?php
/**
* MAGENTO MASS IMPORTER CLI SCRIPT
*
* version : 0.1
* author : S.BRACQUEMONT aka dweeves
* updated : 2010-08-02
*
*/
require_once(dirname(dirname(__FILE__))."/inc/magmi_defs.php");
require_once('magmi_loggers.php');
$script=array_shift($argv);
function buildOptions($argv)
{
$options=array();
foreach($argv as $option)
{
$isopt=$option[0]=="-";
if($isopt)
{
$optarr=explode("=",substr($option,1),2);
$optname=$optarr[0];
if(count($optarr)>1)
{
$optval=$optarr[1];
}
else
{
$optval=1;
}
$options[$optname]=$optval;
}
}
return $options;
}
function getClassInstance($cval,$cdir=".")
{
$cdef=explode(":",$cval);
$cname=$cdef[0];
$cclass=$cdef[1];
$cinst=null;
$cfile="$cdir/$cname.php";
if(file_exists($cfile))
{
require_once($cfile);
if(class_exists($cclass))
{
$cinst=new $cclass();
}
}
if($cinst==null)
{
die("Invalid class definition : ".$cval);
}
return $cinst;
}
function getEngineInstance($options)
{
if(!isset($options["engine"]))
{
$options["engine"]="magmi_productimportengine:Magmi_ProductImportEngine";
}
$enginst=getClassInstance($options["engine"],dirname(dirname(__FILE__))."/engines");
return $enginst;
}
$options=buildOptions($argv);
$importer=getEngineInstance($options);
if(isset($importer))
{
$loggerclass=isset($options['logger'])?$options['logger']:"FileLogger";
$importer->setLogger(new $loggerclass());
if(!isset($options["chain"]))
{
$options["chain"]=isset($options["profile"])?$options["profile"]:"";
$options["chain"].=isset($options["mode"])?":".$options["mode"]:"";
}
$pdefs=explode(",",$options["chain"]);
foreach($pdefs as $pdef)
{
$pm=explode(":",$pdef);
$eargv=array();
if(!empty($pm[0]))
{
$eargv[]="-profile=".$pm[0];
}
if(isset($pm[1]))
{
$eargv[]="-mode=".$pm[1];
}
$eoptions=buildOptions($eargv);
$importer->run(array_merge($eoptions,$options));
}
}
?>
我没有确切的SSH命令,因为它在SSIS组件的代码中。它生成的“详细”日志显示如下:
2015-09-18 16:36:13.459 VERBOSE SshSession(1)[6] SSH: Received packet SSH_MSG_USERAUTH_SUCCESS (1 bytes).
0000 |34 | 4
2015-09-18 16:36:13.459 DEBUG SshSession(1)[6] SSH: Authentication successful.
2015-09-18 16:36:13.459 VERBOSE SshSession(1)[6] SSH: Sending packet SSH_MSG_CHANNEL_OPEN (24 bytes).
0000 |5A-00-00-00-07-73-65-73 73-69-6F-6E-00-00-00-00| Z....session....
0010 |00-02-00-00-00-00-40-00 | ......@.
2015-09-18 16:36:13.490 VERBOSE SshSession(1)[6] SSH: Received packet SSH_MSG_CHANNEL_OPEN_CONFIRMATION (17 bytes).
0000 |5B-00-00-00-00-00-00-00 00-00-00-00-00-00-00-80| [...............
0010 |00 | .
2015-09-18 16:36:13.490 DEBUG SshSession(1)[6] SSH: Executing command 'php /home/flintarm/www/store/magmi-importer/cli/magmi.cli.php -profile=Category -mode=create -logger=CLILogger'.
2015-09-18 16:36:13.490 VERBOSE SshSession(1)[6] SSH: Sending packet SSH_MSG_CHANNEL_REQUEST (128 bytes).
0000 |62-00-00-00-00-00-00-00 04-65-78-65-63-01-00-00| b........exec...
0010 |00-6E-70-68-70-20-2F-68 6F-6D-65-2F-66-6C-69-6E| .nphp /home/flin
0020 |74-61-72-6D-2F-77-77-77 2F-73-74-6F-72-65-2F-6D| tarm/www/store/m
0030 |61-67-6D-69-2D-69-6D-70 6F-72-74-65-72-2F-63-6C| agmi-importer/cl
0040 |69-2F-6D-61-67-6D-69-2E 63-6C-69-2E-70-68-70-20| i/magmi.cli.php
0050 |2D-70-72-6F-66-69-6C-65 3D-43-61-74-65-67-6F-72| -profile=Categor
0060 |79-20-2D-6D-6F-64-65-3D 63-72-65-61-74-65-20-2D| y -mode=create -
0070 |6C-6F-67-67-65-72-3D-43 4C-49-4C-6F-67-67-65-72| logger=CLILogger
2015-09-18 16:36:13.537 VERBOSE SshSession(1)[6] SSH: Received packet SSH_MSG_CHANNEL_WINDOW_ADJUST (9 bytes).
0000 |5D-00-00-00-00-00-20-00 00 | ]..... ..
2015-09-18 16:36:13.537 VERBOSE SshSession(1)[6] SSH: Received packet SSH_MSG_CHANNEL_SUCCESS (5 bytes).
0000 |63-00-00-00-00 | c....