2012-03-29 205 views
2
<?php 
    require_once 'abstract.php'; 

    class Mage_Shell_Snapshot extends Mage_Shell_Abstract 
    { 
    public function _snapshot() 
    { 
     if(!Mage::isInstalled()) 
     { 
      echo "Application is not installed yet, please complete install wizard first."; 
      exit; 
     } 
     # Initialize configuration values 
     $connection = Mage::getConfig()->getNode('global/resources/default_setup /connection'); 
     $rootpath = $this->_getRootPath(); 
     $snapshot = $rootpath.'testing'; 

     # Create the snapshot directory if not exists 
     $io = new Varien_Io_File(); 
     $io->mkdir($snapshot); 

     include('/home/test/public_html/xmlapi.php'); 
     $cp_user="test"; 
     $cp_pass="test123"; 
     $db_host="localhost"; 
     $db_name="test_insatller"; 
     $db_user="test_test"; 
     $db_pass="home123"; 
     $url="http://201.40.548.550/testing/"; 
     $ad_user="admin"; 
     $ad_pass="sk12121"; 
     $ad_email="[email protected]"; 
     $xmlapi = new xmlapi($db_host); 
     $xmlapi->set_port(2083); 
     $xmlapi->password_auth($cp_user,$cp_pass); 
     $xmlapi->set_debug(1); 
     //create database 
     $xmlapi->api1_query($cp_user,"Mysql", "adddb", array($db_name)); 
     //create user 
     $xmlapi->api1_query($cp_user,"Mysql", "adduser", array($db_user,$db_pass)); 
     //add user to database 
     $xmlapi->api1_query($cp_user,"Mysql", "adduserdb", array($db_name,$db_user,'all')); 
     $command = '/home/indieste/public_html/function.sh '.$db_host.' '.$db_name.' '.$db_user.' '.$db_pass.' '.$url.' '.$ad_user.' '.$ad_pass.' '.$ad_email; 
     echo $command; 
     system($command); 
     Mage::log($command); 

    } 
    public function run() 
    { 
     if ($this->getArg('testing')) 
     { 
      $this->_snapshot(); 
     } 
     else 
     { 
      echo $this->usageHelp(); 
     } 
    } 

    public function usageHelp() 
    { 
     global $argv; 
     $self = basename($argv[0]); 

     USAGE; 
    } 
    } 
    $shell = new Mage_Shell_Snapshot(); 
    $shell->run(); 

当我使用putty从文件夹magento->shell->snapshot.php运行此snapshot.php时,它不创建数据库和用户。如何从magento运行bash shell脚本?

我在cPanel中使用xmlapi.php创建数据库和用户,并运行此运行function.sh文件以在cpanel的根目录中安装magento。它也没有给我任何类型的错误。所以,这是代码足以从Magento的运行一个bash shell脚本(function.sh)?

function.sh文件包含与从服务器下载magento相关的命令,将其解压并使用主机名,主机密码,dbname,dbuser,dbpassword,admin用户,管理员密码安装到cpanel的根目录中。

如果任何一个有相关链接,运行从Magento的一个shell脚本,然后请给我,告诉我如何运行Magento的shell脚本?

回答

2

Shell脚本可以从任何PHP应用程序有两种方式运行。

  1. 使用EXEC()函数运行该脚本。

  2. 使用backticks (``)并指定命令,将蜱运行。例如:

$ variable =``ls; ls在反标内。

给出LS的输出入变量。

如果您使用此为应用程序,因为,这是从安全角度来看,一个严重的问题,非常肯定。

+1

我仍然无法创建数据库,但脚本使用exec()运行。谢谢! – Stan 2013-01-11 13:22:37