[英]How to push text into newly created file by shell script from PHP?
我使用PHP網站運行Shell腳本,並在/ opt / xampp / htdocs中創建了所需的名稱文件“ result.txt”。 但是,當應該使用shell腳本的輸出值時,result.txt完全為空。 在終端上嘗試過,在桌面上創建了result.txt並在那里輸出。 在PHP上嘗試過,創建了result.txt,但是里面沒有任何輸出。
這是一個很長的腳本,所以這里是前幾行:
# creates result.txt
touch result.txt
##makes the .txt read only
chmod 444 result.txt
clear
###################################################
# This option audits the password and #
# shadow files on the system #
###################################################
##option 2.1.1
echo -e "=========================================================================================" >> result.txt
echo " SHADOWED PASSWORD CHECK " >> result.txt
echo "=========================================================================================" >> result.txt
任何人?
謝謝。
首先,完全沒有必要重定向每個echo調用的輸出-在Shell腳本的開頭使用此命令將STDOUT重定向到您的輸出文件。
exec &> results.txt
其次-您將chmod設置為444不會使該文件可被Apache / PHP用戶寫入-我會在腳本的最后執行此操作,即使完全需要也可以執行。
首先嘗試使用chdir($ folder)更改工作目錄。
<?php
chdir("/testfolder/");
exec("./script.sh");
?>
但是,為什么不將腳本編寫為php呢? 諸如觸摸,chmod和unix shell中可用的所有其他命令之類的內容都可以在php中輕松獲得。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.