2017-09-25 1 views
0

bash 스크립트가 .PHP 프로그램의 내용을 가져 와서 755 권한을 가진 특정 디렉토리에 작성하는 기능을 자동화하는 기능을 찾고 있습니다. 사용자에게 적절한 프로그램과 파일을 설치하여 웹 사이트를 실행하고 실행시키는이 .sh 스크립트를 제공합니다. 내가 겪고있는 문제는 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

반드시 PHP 코드를 bash 스크립트에 하드 코딩하지 않으시겠습니까? 파일을 복사하고 데이터베이스를 만들면 안됩니까? – 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

관련 문제