Bash 从php文件运行shell脚本

Bash 从php文件运行shell脚本,bash,shell,variables,exec,shell-exec,Bash,Shell,Variables,Exec,Shell Exec,基本上,我正在努力实现以下目标: 1.创建一个php表单以获取新的数据库名称和实例名称。 这是我的a.txt文件: <form class = "myform" action="b.php" method="post"> <h1> Create new instance: </h1> <br> Term1 name: <input type = "textbox" id="dbname" name="dbname"></input

基本上,我正在努力实现以下目标: 1.创建一个php表单以获取新的数据库名称和实例名称。 这是我的a.txt文件:

<form class = "myform" action="b.php" method="post">
<h1> Create new instance: </h1>
<br>
Term1 name: <input type = "textbox" id="dbname" name="dbname"></input>
Term2 name: <input type = "textbox" id="instancename" name="instancename"></input>
<button style "color:red;" type="submit" >create</button>
</form>

创建新实例:

术语1名称: 术语2名称: 创造
二,。将这些参数传递给Shell脚本。这是我的b.php文件:

<?php
$a = $_POST["dbname"];
$b = $_POST["instancename"];
exec("./b.sh $a $b");

将b.sh脚本的完整路径放在php exec语法中,并确保运行web守护进程的用户有权在shell脚本的命令中执行script.ful路径(/usr/bin/dump等),正如我所说,我正确地将参数设置为.sh。问题是(我认为)在shell脚本中使用这些变量的语法。
#!/bin/bash
mysqldump -u root -p'password' currentdb > /home/admin/mydb.sql
echo "create database" $1 | mysql -u root -p'password'
mysql -u root -p'password' $1 < /home/admin/mydb.sql

mkdir /var/www/instance/$2
chmod -R 777 /var/www/instance/$2

cp -r /var/www/instance/current/* /var/www/instance/$2/
cd /var/www/instance/$2/
sed -i 's/currentdb/$1/g' configuration.php