dsa5211314 2016-08-09 23:54
浏览 36

将PHP变量传递给Bash - 不止一个会破坏它

Server 1 : php script

Server 1 sets the $mp3file variable which is received by the bash script on Server 2 as $1

The php script calls ssh2_exec like this (minus all the connection info) :

$stream = ssh2_exec($connection, "/root/incoming/test.sh ".escapeshellarg($mp3file)." &> /dev/null &");

Server 2 : bash script

test.sh (on server 2) contains a simple curl command :

curl -o /path/to/downloaded/file/$1 http://remotefilepath.com/$1

This all works perfectly, and the file is downloaded as expected.

But if I try to pass more than one variable like this :

$stream = ssh2_exec($connection, "/root/incoming/test.sh ".escapeshellarg($mp3file)." ".escapeshellarg($artwork)." &> /dev/null &");

The file is only partially downloaded.

Am I setting multiple variables the wrong way here which is breaking the &> /dev/null & command?

  • 写回答

1条回答 默认 最新

  • dongpi0658 2016-08-10 01:17
    关注

    Ok after some messing around I found the only way I could get it working was by setting the escaped variables first :

    $mp3file = escapeshellarg($mp3file);
    $artwork = escapeshellarg($artwork);
    $title = escapeshellarg($title);
    $safeurl = escapeshellarg($safeurl);
    

    Then passing them like this instead :

    $stream = ssh2_exec($connection, "/root/incoming/test.sh $mp3file $artwork $title $safeurl &> /dev/null &");
    

    I'm not sure that this is the only (or correct) way to do it, but it works.

    评论

报告相同问题?

悬赏问题

  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错