简体   繁体   English

将变量从PHP传递到ubuntu

[英]Passing a variable from PHP to ubuntu

I want to run a script on my ubuntu server with a variable from php in it. 我想在ubuntu服务器上运行一个脚本,其中包含来自php的变量。

Here are some of the things i've tried to pass a variable to ubuntu... 这是我尝试将变量传递给ubuntu的一些方法...

shell_exec('vpsName=HI3');

vpsName=`mysql -D jake_db -h 127.0.0.1 -u jake -pXXXXXXX -se "SELECT vpsName FROM reinstalls WHERE status = 'pending'"`;

The final way in which i thought I could fix it was to avoid running the script through ubuntu all together and run it from shell_exec(); 我认为可以解决的最后一种方法是避免同时通过ubuntu运行脚本,并从shell_exec()运行它; but it fails on running the guestfish commands. 但在运行guestfish命令时失败。

Here is my entire reinstalls.sh script. 这是我的整个reinstalls.sh脚本。

    sudo rm /var/lib/libvirt/images/"$vpsName".qcow2 && sudo wget -O /var/lib/libvi$
guestfish -a /var/lib/libvirt/images/"$vpsName".qcow2 <<'EOF'
 run
 mount /dev/ubuntu-vg/root /
  rm /etc/network/interfaces
EOF
sudo fusermount -u /mnt && virsh start "$vpsName" && echo "IT WORKED!"

I am open to any way of getting this to work, as long as its secure, Thanks in advance, Jake 只要安全,我愿意采取任何方式使其工作,在此先感谢杰克

EDIT: 编辑:
If I run the script with a VPS name instead of a variable, it works. 如果我使用VPS名称而不是变量来运行脚本,那么它将起作用。 I just can't find a way to pass the variables from the website to the ubuntu16.04 OS. 我只是找不到将变量从网站传递到ubuntu16.04 OS的方法。

Well one way would be to run each command from PHP: 一种方法是从PHP运行每个命令:

shell_exec("sudo rm /var/lib/libvirt/images/" . $vpsName . ".qcow2");
shell_exec("sudo wget -O /var/lib/libvi ... etc");

The other would be to invoke your shell script from PHP, passing the vps name as a parameter: 另一种是从PHP调用您的shell脚本,并将vps名称作为参数传递:

shell_exec("reinstalls.sh " . $vpsName)

But then you'd have to rewrite the shell script to pick up the command line parameter and apply it as necessary. 但随后,您将不得不重写Shell脚本以选择命令行参数并根据需要应用它。 In the case of bash, this explains how to go about that. 就bash而言, 说明了解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM