这应该使用Curl在远程服务器上调用php脚本。如果您插入值而不是变量,那么curl命令将起作用,因此我知道语法在这里不可用。
但是,对我来说奇怪的是,当它抓住变量时,结果总是成功的。有任何想法吗?预先感谢!
#!/bin/bash
# this script should call the curl command to run the php script
# on the web server and log the user in openvpn client
echo Enter Account Number:
read accountNum
echo Enter Password:
read pwVar
# curl command to run php script on web server
authResult=$(curl -X POST IPADDRESSOFSERVERREMOVED -d '{"accountNumber":"$accountNum","password":"$pwVar"}' -H 'Content-Type: application/json')
authResult2=$(echo "$authResult")
if [ authResult2=$(echo "$authResult" | grep "successfully") ]
then
echo yep it works
else
echo no it dont
fi
答案 0 :(得分:0)
非常抱歉重复。这样重写就可以了:
#!/bin/bash
# this script should call the curl command to run the php script
# on the web server and log the user in openvpn client
echo Enter Account Number:
read accountNum
echo Enter Password:
read pwVar
# curl command to run php script on web server
authResult=$(curl -X POST ADDRESSREMOVEDHERE -d '{"accountNumber":"'$accountNum'","password":"'$pwVar'"}' -H 'Content-Type: application/json')
if [ [ $authResult = *"success"* ] ]; then
echo yep it works
else
echo no it dont
fi