我想从PHP脚本执行系统中存在的Bash脚本.我在系统上有两个脚本.其中一个是名为client.phppresent at 的PHP脚本/var/www/html,另一个是名为testscriptpresent at 的Bash脚本/home/testuser.
我的client.php脚本看起来像
<?php
$message=shell_exec("/home/testuser/testscript 2>&1");
print_r($message);
?>
Run Code Online (Sandbox Code Playgroud)
我的测试文件看起来像
#!/bin/bash
echo "Testscript run succesful"
Run Code Online (Sandbox Code Playgroud)
当我在终端上执行以下操作时
php client.php
Run Code Online (Sandbox Code Playgroud)
我在终端上得到以下输出
Testscript run successful
Run Code Online (Sandbox Code Playgroud)
但是当我打开页面时
http://serverdomain/client.php
Run Code Online (Sandbox Code Playgroud)
我得到以下输出
sh: /home/testuser/testscript: Permission denied
Run Code Online (Sandbox Code Playgroud)
即使我做了chmod + x testscript后,我也收到了这个错误.
如何从浏览器中使用它?请帮忙.
我已经在我的机器上安装了postfix,我正在以编程方式(使用python)动态更新virtual_alias(在某些操作上).一旦我更新/ etc/postfix/virtual_alias中的条目,我就运行命令:
sudo /usr/sbin/postmap /etc/postfix/virtual_alias 2>>/work/postfix_valias_errorfileRun Code Online (Sandbox Code Playgroud)但是我收到了错误:sudo: sorry, you must have a tty to run sudoRun Code Online (Sandbox Code Playgroud)
我想以非人类的方式运行提到的sudo命令(意思是,我从python脚本运行这个系统命令.).那么如何以编程方式运行此命令?
我想在我的aws linux服务器上将文件从doc转换为pdf.在我以前的机器上它工作正常,但现在我的新机器出现问题.唯一的区别是我已经从PHP 7.0升级到PHP 7.2.和libre办公室版本
LibreOffice 6.0.1.1 00m0(Build:1)
我已经尝试为libreoffice和执行命令的包提供root权限但没有成功.
这是我正在使用的软件包https://github.com/szonov/libreoffice-converter
我正在使用laravel 5.4.这是执行操作的包中的代码
$replacement = array(
'bin' => $this->bin,
'convert_to' => $convert_to,
'outdir' => $outdir,
'source' => $this->source
);
$cmd = $this->makeCommand($replacement);
$cmd = "sudo ".$cmd;
shell_exec($cmd);
$result = false;
if (file_exists($outfile)) {
$this->mkdir(dirname($this->destination));
$result = rename($outfile, $this->destination);
}
// remove temporary sub directory
rmdir($outdir);
return $result;
Run Code Online (Sandbox Code Playgroud)
我尝试追加sudo,因为当我执行命令并执行使用sudo时,它在命令行中工作.
ssh_exec()拒绝在Windows中执行命令,我遇到了一个噩梦.
这是我的代码:
<?php
$connection = ssh2_connect('localhost', 22);
ssh2_auth_none($connection, 'root');
$stream = ssh2_exec($connection, 'C:\Program Files\CCleaner\CCleaner.exe',FALSE);
?>
Run Code Online (Sandbox Code Playgroud)
它向我显示以下警告:Unable to request a channel from remote host in.如果您有任何提示,请告诉我.谢谢.