1

This is supposed to call a php script on a remote server using Curl. The curl command works if you plug in values instead of variables, so I know the syntax is off here.

However, the odd part to me is that the result is always successful when it greps the variable. Any ideas? Thanks in advance!

#!/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
superKing
  • 79
  • 1
  • 6
  • 14
  • 1
    superKing, in SO's system, this is a duplicate even though the linked question isn't the 100% specific answer. Tying it in with this question, `-d '{"accountNumber":"$accountNum","password":"$pwVar"}'` has the `$...` within `''`. Try `-d '{"accountNumber":"'$accountNum'","password":"'$pwVar'"}'` (as long as `$accountNum` and `$pwVar` don't have spaces or special-to-`bash` characters in them). – cxw Aug 31 '18 at 00:12

1 Answers1

0

Thanks sorry for the duplicate. Re-written like this it works:

#!/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
superKing
  • 79
  • 1
  • 6
  • 14