簡體   English   中英

在PHP中運行bash shell腳本時未創建目錄

[英]directory is not creating while running bash shell script in php

我想在php執行bash shell腳本。 用於創建目錄的shell腳本。 但是,當我在服務器上運行.php文件時,它沒有創建。

以上我使用的PHP代碼---

<html>
<?php
echo exec('./home/biswajit/lh.sh')
?>
thanx
</html>

相應的lh.sh文件的代碼是------

#!/bin/bash

cat <<EOF | /home/biswajit/matlab  -nodesktop -nosplash -nodisplay /> /home/biswajit/matlab_result.out
mkdir('/home/biswajit/Done');
disp('directory created');
exit
EOF

檢查運行哪個用戶的權限。 您可以回顯“ whoami”(bash)命令的輸出,以了解使用哪個用戶來運行腳本。

例如,如果使用“ www-data”用戶(ubuntu的[和也許其他人]默認的httpd用戶)執行該文件,則它可能無權在用戶的主文件夾中創建目錄。

我最近發布了一個項目,該項目允許PHP獲取和與真實的Bash shell(如果需要,請作為根)進行交互,它解決了exec()和shell_exec()的局限性。 在這里獲取它: https : //github.com/merlinthemagic/MTS

下載后,您只需使用以下代碼:

$shell    = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1  = $shell->exeCmd('cat <<EOF | /home/biswajit/matlab  -nodesktop -nosplash -nodisplay /> /home/biswajit/matlab_result.out');
$return2  = $shell->exeCmd('mkdir -p \'/home/biswajit/Done\'');

//the return will be a string containing the return of the command
echo $return1;
echo $return2;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM