2017-09-25 5 views
0

bashスクリプトが.PHPプログラムの内容を取得し、権限が755の特定のディレクトリに作成する機能を自動化する機能を探しています。ユーザーにこの1つの.shスクリプトを与え、適切なプログラムとファイルをインストールしてWebサイトを起動して実行させます。私が実行している問題は、PHP変数が出力ファイルに保存されないことです。PHPプログラムを作成できるbashシェルスクリプトを作成する

echo "<?php 
header('Content-Type: text/xml'); 
require_once '/var/www/osbs/PHPAPI/account.php'; 
require_once '/var/www/osbs/zang/library/Zang.php'; 
$To = $_POST['subject']; 
$Body = $_POST['text']; 
# If you want the response decoded into an Array instead of an Object, set 
response_to_array to TRUE, otherwise, leave it as-is 
$response_to_array = false; 
# Now what we need to do is instantiate the library and set the required 
options defined above 
$zang = Zang::getInstance(); 
# This is the best approach to setting multiple options recursively Take note that you cannot set non-existing options 
$zang -> setOptions(array(
'account_sid' => $account_sid, 
'auth_token' => $auth_token, 
'response_to_array' => $response_to_array)); 
?>" | tee /var/www/output.php 

output.phpファイルは君たちを助けることができる$で始まるすべての変数が欠落しています。私は、次のコマンドを使用していますか?

+0

あなたは、文字通り、あなたのbashスクリプトにいくつかのPHPコードをハードコードしたくないのですか?単にファイルをコピーしたり、データベースを作成したりするべきではありませんか? – ADyson

+0

バックスラッシュ '\ $' –

+0

でbashスクリプトの '$'をエスケープするか、bashスクリプトのPHPコードの前後に一重引用符を使用する必要があります。 –

答えて

1

ここに引用問題を処理する最も簡単な方法は、使用することです"here-doc"teeの必要はありません

cat >/var/www/output.php <<"EOF" 
<?php 
header('Content-Type: text/xml'); 
require_once '/var/www/osbs/PHPAPI/account.php'; 
require_once '/var/www/osbs/zang/library/Zang.php'; 
$To = $_POST['subject']; 
$Body = $_POST['text']; 
# If you want the response decoded into an Array instead of an Object, 
# set response_to_array to TRUE, otherwise, leave it as-is 
$response_to_array = false; 
# Now what we need to do is instantiate the library and set the 
# required options defined above 
$zang = Zang::getInstance(); 
# This is the best approach to setting multiple options recursively. 
# Take note that you cannot set non-existing options 
$zang -> setOptions(array(
'account_sid' => $account_sid, 
'auth_token' => $auth_token, 
'response_to_array' => $response_to_array)); 
?> 
EOF 

(あなたが本当に不要と思われるコンソールにすべてのものをダンプする場合を除き) 。区切り文字列(<<"EOF")を引用すると、here-doc全体が効果的に引用され、変数の展開が妨げられます。

+0

ありがとう!魅力的に働いた – fixnode

関連する問題