Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash不能通过php工作_Php_Bash_Shell - Fatal编程技术网

bash不能通过php工作

bash不能通过php工作,php,bash,shell,Php,Bash,Shell,我可以手动运行这个脚本,它在crontab中写入。但是当我用php执行下面的脚本时。事实并非如此。但上面写着“bash不起作用” '#!/bin/bash '."\n".'(crontab -l ; echo "13 * * * * /usr/local/apache2/htdocs/etools6/scheduler/etbat.sh" ) 2>&1 | grep -v "no crontab" | sort | uniq | crontab -'; 上述代码存储在一个名为ba

我可以手动运行这个脚本,它在crontab中写入。但是当我用php执行下面的脚本时。事实并非如此。但上面写着“bash不起作用”

'#!/bin/bash '."\n".'(crontab -l ; echo "13 * * * * /usr/local/apache2/htdocs/etools6/scheduler/etbat.sh" ) 2>&1 | grep -v "no crontab" | sort | uniq | crontab -';
上述代码存储在一个名为batfile.sh的文件中

$batfile = batfile.sh;

chdir(getcwd());
shell_exec("chmod -R 777 ".getcwd().'/'.$batfile);
shell_exec("chmod +x ".getcwd().'/'.$batfile);
$output = shell_exec('/bin/bash ./'.$batfile) or die('bash didn't work');
echo $output;
我无法在这个论坛上找到解决方案,这就是我在这里写这篇文章的原因


这一部分不是通过php执行的

$output = shell_exec('/bin/bash ./'.$batfile) or die('bash didn't work');

您想做什么?此部分没有执行('/bin/bash./'.$batfile)或死亡('bash不工作')实际上$batfile不是文件名或目录,命令chmod在file或directory上运行您似乎在
batfile
中有脚本的内容,但从未将其写入任何文件。如果所有引用都正确,请尝试使用
bash-c
运行它,或者先将其写入一个文件,然后执行该文件,不要
die
并查看错误消息(如果有)。