How do i call bash script function using exec function by passing parameter in php?
Posted
by
Stan
on Stack Overflow
See other posts from Stack Overflow
or by Stan
Published on 2012-03-21T07:14:18Z
Indexed on
2012/04/08
17:29 UTC
Read the original article
Hit count: 295
I have created a bash script that install magento in a cpanel. but i have a problem regarding the exec function.
$function_path = Mage::getBaseDir()."/media/installer/function.sh";
exec("$function_path $db_host $db_name $db_user $db_pass $url $ad_user $ad_pass $ad_email");
This the bash shell script function.sh #!/bin/bash
magento_detail $dbhost $dbname $dbuser $dbpass $url $admin_username $admin_password $admin_email function magento_detail() {
stty erase '^?'
echo "To install Magento, you will need a blank database ready with a user assigned to it."
echo -n "Do you have all of your database information"
dbinfo = "y"
echo $dbinfo
if [ "$dbinfo" -eq 'y' ]
then
echo "Database Host (usually localhost) : $dbhost "
echo "Database Name : $dbname "
echo "Database User : $dbuser "
echo "Database Password : $dbpass "
echo "Store Url : $url "
echo "Admin Username : $admin_username "
echo "Admin Password : $admin_password "
echo "Admin Email Address : $admin_email "
echo -n "Include Sample Data? (y/n) "
echo sample = "y"
if [ "$sample" -eq "y" ];
then
echo
echo "Now installing Magento with sample data..."
echo
echo "Downloading packages..."
echo
wget http://www.magentocommerce.com/downloads/assets/1.5.1.0/magento-1.5.1.0.tar.gz
wget http://www.magentocommerce.com/downloads/assets/1.2.0/magento-sample-data-1.2.0.tar.gz
echo
echo "Extracting data..."
echo
tar -zxvf magento-1.5.1.0.tar.gz
tar -zxvf magento-sample-data-1.2.0.tar.gz
echo
echo "Moving files..."
echo
mv magento-sample-data-1.2.0/media/* magento/media/
mv magento-sample-data-1.2.0/magento_sample_data_for_1.2.0.sql magento/data.sql
mv magento/index.php magento/.htaccess ./$test1
echo
echo "Setting permissions..."
echo
chmod o+w var var/.htaccess app/etc
chmod -R o+w media
echo
echo "Importing sample products..."
echo
mysql -h $dbhost -u $dbuser -p$dbpass $dbname < data.sql
echo
echo "Initializing PEAR registry..."
echo
chmod 550 mage
./mage mage-setup .
echo
echo "Downloading packages..."
echo
echo
echo "Cleaning up files..."
echo
rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*
rm -rf magento/ magento-sample-data-1.2.0/
rm -rf magento-1.5.1.0.tar.gz magento-sample-data-1.2.0.tar.gz data.sql
rm -rf index.php.sample .htaccess.sample php.ini.sample LICENSE.txt STATUS.txt data.sql
echo
echo "Installing Magento..."
echo
php -f install.php --license_agreement_accepted "yes" --locale "en_US" --timezone "America/Los_Angeles" --default_currency "USD" --db_host "$dbhost" --db_name "$dbname" --db_user "$dbuser" --db_pass "$dbpass" --url "$url" --use_rewrites "yes" --use_secure "no" --secure_base_url "" --use_secure_admin "no" --admin_email "$admin_email" --admin_username "$admin_username" --admin_password "$admin_password"
echo
echo "Finished installing Magento"
echo
exit
else
echo "Now installing Magento without sample data..."
echo
echo "Downloading packages..."
echo
wget http://www.magentocommerce.com/downloads/assets/1.5.1.0/magento-1.5.1.0.tar.gz
echo
echo "Extracting data..."
echo
tar -zxvf magento-1.5.1.0.tar.gz
echo
echo "Moving files..."
echo
mv magento/* magento/.htaccess .
echo
echo "Setting permissions..."
echo
chmod o+w var var/.htaccess app/etc
chmod -R o+w media
echo
echo "Initializing PEAR registry..."
echo
chmod 550 mage
./mage mage-setup .
echo
echo "Downloading packages..."
echo
echo
echo "Cleaning up files..."
echo
rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*
rm -rf magento/ magento-1.5.1.0.tar.gz
rm -rf index.php.sample .htaccess.sample php.ini.sample LICENSE.txt STATUS.txt
echo
echo "Installing Magento..."
echo
php -f install.php --license_agreement_accepted "yes" --locale "en_US" --timezone "America/Los_Angeles" --default_currency "USD" --db_host "$dbhost" --db_name "$dbname" --db_user "$dbuser" --db_pass "$dbpass" --url "$url" --use_rewrites "yes" --use_secure "no" --secure_base_url "" --use_secure_admin "no" --admin_email "$admin_email" --admin_username "$admin_username" --admin_password "$admin_password"
echo
echo "Finished installing Magento else part"
exit
fi
else
echo "Please setup a database first. Don't forget to assign a database user!"
exit
fi
}`
when i run this exec command,at that time it calls bash script function magento_installer() which contains arguments $db_host $db_name $db_user $db_pass $url $ad_user $ad_pass $ad_email.
above arguments i'll pass in exec command to call magento_installer() function of bash script.
so, is it right way of calling a bash script function?
It directly goes to the last step of if condition and prints "Please setup a database first. Don't forget to assign a database user!". It cant enter it in if condition and directly goes to else condition. so please help me?
© Stack Overflow or respective owner