在PHP运行bash脚本 [英] running bash scripts in php

查看:87
本文介绍了在PHP运行bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两台电脑。在第一台计算机我的Apache和所有我的网络code运行。在第二台计算机我有大量的存储与检索脚本的数据(脚本通常需要几个小时运行)。我基本上是创建一个web用户界面没有任何时间延迟访问这些数据。

I have two computers. On the first computer I have apache running with all my web code. On the second computer I have large amounts of data stored with a retrieval script (the script usually takes hours to run). I am essentially creating a web UI to access this data without any time delay.

所以我呼吁:

EXEC(庆典initial.bash);

这是一个驱动程序的脚本,在我的Apache的文件夹中。它调用其他计算机上运行脚本。
电话:
SSH otherMachine temp.bash&安培;

this is a driver script that is in my Apache folder. It calls the script on the other computer. calling: ssh otherMachine temp.bash&

本脚本调用第二台计算机上的数据检索脚本。

this script invokes the data retrieval script on the second computer.

如果我在终端呼叫initial.bash,一切工作顺利和圆满,但如果我把它在我的PHP文件,然后在initial.bash运行所有我的命令,与例外 SSH otherMachine temp.bash&安培; 。我把和放大器;在那年底,使temp.bash会在后台运行,因为它需要几个小时才能完成。

If I call initial.bash in the terminal, everything works smoothly and successfully, but if I call it in my PHP file, then all my commands in initial.bash run, with the exception of ssh otherMachine temp.bash&. I put the & at the end of that, so that temp.bash will run in the background, since it does take a few hours to complete.

我不知道为什么,当被Apache调用的嵌套脚本没有运行。难道还有比使用EXEC或到了shell_exec调用脚本,最终调用另一个脚本一个更好的选择。我不叫第二台机器上的脚本的直接原因是因为它需要的程序运行的时间。直到脚本完成了shell_exec不使PHP页面。

I am not sure why the nested script is not running when invoked by Apache. Is there a better alternative than using exec or shell_exec to call a script, which ultimately calls another script. The reason I don't call a script on the second machine directly is because of the time it takes the program to run. Shell_exec does not render the php page until the script is complete.

推荐答案

一对夫妇建议:


  1. 尝试把完整路径SSH(的/ usr / bin中/ SSH 或其它地方它的安装,而不是仅仅 SSH

  1. Try putting the full path to ssh (/usr/bin/ssh or wherever it's installed instead of just ssh)

请确保用户阿帕奇/ PHP下运行设置正确使用SSH不要求输入密码来othermachine。显然,如果SSH要求输入密码,没有人在那里键入它,所以它只是似乎没有做任何事情。

Make sure the user apache/PHP is running under is set up correctly to ssh to othermachine without asking for a password. Obviously if SSH asks for a password, there is nobody there to type it in, so it will just appear to have done nothing.

尝试重定向输出,以及 - SSH othermachine temp.bash>的/ dev / null的2 - ;&放大器; 1安培;

Try redirecting outputs as well -- ssh othermachine temp.bash >/dev/null 2>&1 &

尝试一些不同的标志为SSH。像 -n 这是专门为在后台通过SSH运行命令而设计的。

Try some different flags to ssh. Like -n which is specifically designed for running a command over ssh in the background.

这篇关于在PHP运行bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆