1
<?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();

When i run this snapshot.php from the folder magento->shell->snapshot.php using putty, it is not creating the database and user.

I am creating the database and user in cpanel using xmlapi.php and run this run function.sh file to install magento in root directory of cpanel. It is also not giving me any type of error. so, is this code is sufficient to run a bash shell script(function.sh) from magento ?.

function.sh file contains the command related to download magento from server, extract it, and install in the root directory of cpanel using hostname, hostpassword, dbname, dbuser,dbpassword,admin user, admin password.

If any one have related link to run a shell script from magento then pls give me and tell me how to run a shell script from magento?.

2 Answers 2

2

Shell scripts can be run from any php applications in two ways.

  1. Use the exec() function to run the script.

  2. use backticks (``) and specify the command to be run in the ticks. eg:

$variable= ``ls; ls inside the backtick.

gives the output of ls into the variable.

Be very sure if you are using this for an application , because, this is one serious issue from security perspective.

Sign up to request clarification or add additional context in comments.

1 Comment

I still haven't been able to create the database but the script is run using exec(). Thanks!
2

Refer to the article:
http://www.magentocommerce.com/wiki/how_to_-_import_manufacturers_or_any_other_option_attribute_set
Which uses shell script for importing manufacturers.

Hope this helps.

1 Comment

I am already used that code but it is not create the database in cpanel and the script is not running from this code using command prompt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.