dsf12313 2017-05-01 13:10
浏览 53
已采纳

将变量从PHP传递给ubuntu

I want to run a script on my ubuntu server with a variable from php in it.

Here are some of the things i've tried to pass a variable to 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(); but it fails on running the guestfish commands.

Here is my entire reinstalls.sh script.

    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. I just can't find a way to pass the variables from the website to the ubuntu16.04 OS.

  • 写回答

1条回答 默认 最新

  • douhuan1497 2017-05-01 13:36
    关注

    Well one way would be to run each command from 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:

    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. In the case of bash, this explains how to go about that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog