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 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab