2015-09-18 126 views
0

PHP腳本我有打電話給一個PHP腳本接受參數..與運行在非交互式SSH會話參數不工作

php /home/flintarm/www/store/magmi-importer/cli/magmi.cli.php -profile=Category -mode=create -logger=CLILogger 

如果我登錄用膩子,並具有交互式登錄這工作完全正常。

我想從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      | [email protected] 
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.... 
+0

表明您已經執行SSH命令。 – Barmar

+1

幾件事情可供您編輯進您的問題:通過SSH發送的命令是什麼?通過「踢開php」,你的意思是它運行腳本?或者只是PHP一般? 如果腳本本身正在運行,請嘗試使用'print_r($ argv)',以便看到PHP如何看到傳遞的參數。這可能是它們在第一個參數中混在一起,或完全丟失,具體取決於通過SSH發送的命令。 –

+0

我更新了帖子以顯示來自SSIS的日誌SSH addon – user1005246

回答

0

當您啓動一個非交互式會話,一組不同的啓動腳本的運行和/或腳本不同的路徑採取(基於TTY變量) 。

所以你的環境可能(最有可能)有所不同。

這可能會影響PHP腳本的執行。在你的情況下,你可能沒有啓用register_argc_argv。所以$argv沒有設置。

我建議你重寫你的腳本,不要依賴於非默認的PHP設置。特別是使用$_SERVER["argv"]而不是。

或者將phpinfo()放在腳本的開頭,以交互方式和非交互方式運行它,並查看造成PHP配置差異的原因。然後,更正啓動腳本,爲交互式和非交互式會話設置相同的PHP配置。


或者,如果你不想用腳本一塌糊塗,把這個在開始的時候:

$argv = $_SERVER["argv"]; 
+0

我試過-n選項..它應該使用默認設置,允許register_argc_argv是活動的,它沒有工作.. I AM DONE搞亂了這個不需要.. 在一個PHP腳本..我怎麼能重寫傳入的參數,並提供我自己的腳本手動? – user1005246

+0

'register_argc_argv'默認是關閉的。 –

+0

無論如何,將'$ _SERVER [「argv」]'複製到'$ argv'中怎麼辦?看到我編輯的答案。 –

相關問題