[英]Php executing a bash script with at command
您好,我正在嘗試在我的 php 腳本中執行一個 shell 命令,但它不起作用。 我的 php 腳本:
//I save the Order
$holdedOrder->save();
$id = $holdedOrder->id;
$old_path = getcwd();
chdir(__DIR__.'/../');
$scriptFile = 'anacron_job_unhold_order.sh';
$bool = file_exists($scriptFile);
//$bool is true !
//this command works in shell but not in here do not know why
$s = shell_exec("echo \"/usr/bin/bash $scriptFile $id\" | /usr/bin/at now +$when");
chdir($old_path);
return [$s,$bool];
$when 的有效值是4 hours
或4 days
......命令將是:
echo bash anacron_job_unhold_order.sh 29 | at now +1 minutes
輸出為空。 嘗試使用exec()
返回 127 代碼
編輯:我從 /etc/at.deny 中刪除了 www-data 並且仍然存在同樣的問題
命令shell_exec("echo \\"/usr/bin/bash $scriptFile $id\\" | /usr/bin/at now +$when");
可能是導致問題的原因,您應該仔細看看at
是如何工作的。
命令應該是這樣的
at [options] [job...]
要從命令而不是 STDIN 向at
提供作業,請使用heredoc syntax
at now + 1 minute <<< 'touch /tmp/test'
所以 PHP 代碼應該是這樣的;
$s = shell_exec("/usr/bin/at now + {$when} <<< '/usr/bin/bash {$scriptFile} {$id}'");
exec($s, $output, $return_var);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.