通过PHP执行.sh脚本 [英] Executing .sh scripts via PHP

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

问题描述

我有一些游戏服务器需要运行shell脚本以确保质量.我试图弄清楚如何通过同一服务器上的网页运行这些脚本.这是Ubuntu专用服务器.

I have a few game servers that that I need to run shell scripts for frequality. I'm trying to figure out how to run these scripts via a webpage on the same server. It's a Ubuntu Dedicated server.

网站文件位于/var/www/...中.我需要手动运行的.sh文件位于/home/amservers/.../start中.sh .

The website files are located via /var/www/... The .sh files I need to manually run are located in /home/amservers/.../start.sh.

我查看了其他答案,但仍然无法弄清楚.如何找到文件并存储并运行exec()?

I've looked at other answers and I still can't figure it out. How do locate the files and store it and then run exec()?

推荐答案

您可以在PHP中使用shell_exec()函数:

You could just use the shell_exec() function in PHP:

http://php.net/manual/en/function.shell-exec.php

shell_exec('sh script.sh');

如果要使用变量(bash中的$ 1,$ 2等),则可以键入:

And if you want to use the variables ($1, $2 etc. in bash) you could just type:

shell_exec('sh script.sh variable1 variable2');

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

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