1
我創建了一個在cPanel中安裝magento的bash腳本。但我有關於exec函數的問題。如何通過傳遞參數在PHP中使用exec函數調用bash腳本函數?
$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");
在執行函數,我通過在shell腳本將需要創建一個Magento的DATABSE並安裝它的所有參數。這是在bash shell腳本代碼寫在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
}`
我的問題是,它不執行腳本的所有命令,並直接進入的如果最後一步條件和打印「請先設置數據庫,不要忘記指定數據庫用戶!」。任何人都可以告訴我的乳清該劇本跳過如果部分,直接去其他部分?
你究竟是在執行shell? – 2012-03-21 07:16:35
請發佈你的命令和參數的concate exec字符串! – silly 2012-03-21 07:27:41
你說你有問題,但你不告訴我們是什麼。然後你通過*詢問我們是什麼來增加這一點。所以我不得不懷疑。 。 。你怎麼知道你有問題? – ruakh 2012-03-21 13:42:42