卷曲shell脚本没有给php文件的变量

时间:2015-06-15 11:15:38

标签: php mysql shell curl

我想要什么

使用Apple脚本我从本地计算机上获取一些信息。现在我希望将这些信息写入MySQL数据库。

我的代码

现在我正在获取所有信息并将其写入变量。然后我创建一个URL来将这些信息传递给我的PHP脚本,该脚本处理写入数据库的内容。在这个创建的URL字符串中,我用“%20”替换所有空格(因为URL友好性)。

现在我正在运行一个shell脚本,其中curl导航到指定的URL。

set aString to "http://localhost/clientinfo/setlogin.php?a=" & info_hostname & "&b=" & info_modelname & "&c=" & info_macaddress & "&d=" & info_osversion & "&e=" & info_cpuname & "&f=" & info_cpuspeed & "&g=" & info_ram & "&h=" & info_serial

set my text item delimiters to " "
set split_list to every text item of aString
set my text item delimiters to "%20"
set newString to (split_list as text)

do shell script "curl " & newString

在所有编码之后生成的URL如下所示:

  

http://localhost/clientinfo/setlogin.php?a=hostname&b=Mac%20mini&c=0c:4d:e9:ee:d5:58&d=10.9&e=Intel%20Core%20i5&f=2.5%20GHz&g=8%20GB&h=C07MW1XMH

问题

PHP脚本告诉我,未指定第一个之后的所有其他"$_GET"变量。

卷曲输出片段:

<b>Notice</b>:  Undefined index: b in <b>setlogin.php</b> on line <b>5</b><br />

当我输出生成的URL并将其输入浏览器的地址栏时,它可以正常工作。

curl脚本有什么问题?

1 个答案:

答案 0 :(得分:0)

你的脚本的最后一行是调用curl和生成的查询,问题似乎是通过shell运行并且&amp;它是一个特殊的角色(把东西放在背景上)所以你可能需要使用引号来避免被解释的字符串

do shell script "curl \"" & newString & "\""