1

I am trying to create a little shellscript using curl.

This is the script(i need to hide the username,url & Co.)

for i in `cat cain.txt`
do
uuid=$(curl   -X POST -H "ACCEPT-LANGUAGE:en"   -H "Content-Type:application/json"   -H "Accept: application/json" -d  {"username":"TheUserName"}  HereTheUrl) 
> final.txt
fuid=$(echo "$uuid" | sed -nE 's/.*"serviceUuid":"(.*)","user.*/\1/p' >>  final.txt)
eval $fuid
echo $fuid

service_uuid=$(cat final.txt)
password=$(sed -n 1p cain.txt)
echo $service_uuid
echo $password

login=$(curl -X POST -H "ACCEPT-LANGUAGE:en"  -H "Content-Type: application/json;charset=utf-8"  -H "Accept-Encoding:gzip,deflate"   -H "Accept: application/json"  -H "Connection: keep-alive" -d  {"serviceUuid":"${service_uuid}","password":"${password}"}  HereTheUrl)

echo "$login"
if [ "$login" = "STATUS_OK" ]
then
echo "Password: $password"
break
else
echo "Trying: $password"
fi
done

Now when i run this i have this error:

{"status":{"code":"SERVER_ERROR","message":"java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"},"body":{"data":{"detailMessage":"java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $","cause":{"detailMessage":"Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $","stackTrace":[{"declaringClass":"com.google.gson.stream.JsonReader","methodName":"beginObject","fileName":"JsonReader.java","lineNumber":385},{"declaringClass":"com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter","methodName":"read","fileName":"ReflectiveTypeAdapterFactory.java","lineNumber":213},{"declaringClass":"com.google.gson.Gson","methodName":"fromJson","fileName":"Gson.java","lineNumber":887},{"declaringClass":"com.google.gson.Gson","methodName":"fromJson","fileName":"Gson.java","lineNumber":852},{"declaringClass":"com.teamdae.common.arch.jax.handler.GsonMessageBodyHandler","methodName":"readFrom","fileName":"GsonMessageBodyHandler.java","lineNumber":91},{"declaringClass":"org.apache.cxf.jaxrs.utils.JAXRSUtils","methodName":"readFromMessageBodyReader","fileName":"JAXRSUtils.java","lineNumber":1342},{"declaringClass":"org.apache.cxf.jaxrs.utils.JAXRSUtils","methodName":"readFromMessageBody","fileName":"JAXRSUtils.java","lineNumber":1293},{"declaringClass":"org.apache.cxf.jaxrs.utils.JAXRSUtils","methodName":"processParameter","fileName":"JAXRSUtils.java","lineNumber":826},{"declaringClass":"org.apache.cxf.jaxrs.utils.JAXRSUtils","methodName":"processParameters","fileName":"JAXRSUtils.java","lineNumber":789},{"declaringClass":"org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor","methodName":"processRequest","fileName":"JAXRSInInterceptor.java","lineNumber":212},{"declaringClass":"org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor","methodName":"handleMessage","fileName":"JAXRSInInterceptor.java","lineNumber":77},{"declaringClass":"org.apache.cxf.phase.PhaseInterceptorChain","methodName":"doIntercept","fileName":"PhaseInterceptorChain.java","lineNumber":308},{"declaringClass":"org.apache.cxf.transport.ChainInitiationObserver","methodName":"onMessage","fileName":"ChainInitiationObserver.java","lineNumber":121},{"declaringClass":"org.apache.cxf.transport.http.AbstractHTTPDestination","methodName":"invoke","fileName":"AbstractHTTPDestination.java","lineNumber":254},{"declaringClass":"org.apache.openejb.server.cxf.rs.CxfRsHttpListener","methodName":"doInvoke","fileName":"CxfRsHttpListener.java","lineNumber":251},{"declaringClass":"org.apache.tomee.webservices.CXFJAXRSFilter","methodName":"doFilter","fileName":"CXFJAXRSFilter.java","lineNumber":94},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"internalDoFilter","fileName":"ApplicationFilterChain.java","lineNumber":192},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"doFilter","fileName":"ApplicationFilterChain.java","lineNumber":165},{"declaringClass":"org.apache.tomcat.websocket.server.WsFilter","methodName":"doFilter","fileName":"WsFilter.java","lineNumber":52},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"internalDoFilter","fileName":"ApplicationFilterChain.java","lineNumber":192},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"doFilter","fileName":"ApplicationFilterChain.java","lineNumber":165},{"declaringClass":"org.apache.catalina.filters.HttpHeaderSecurityFilter","methodName":"doFilter","fileName":"HttpHeaderSecurityFilter.java","lineNumber":120},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"internalDoFilter","fileName":"ApplicationFilterChain.java","lineNumber":192},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"doFilter","fileName":"ApplicationFilterChain.java","lineNumber":165},{"declaringClass":"org.apache.catalina.core.StandardWrapperValve","methodName":"invoke","fileName":"StandardWrapperValve.java","lineNumber":198},{"declaringClass":"org.apache.catalina.core.StandardContextValve","methodName":"invoke","fileName":"StandardContextValve.java","lineNumber":108},{"declaringClass":"org.apache.tomee.catalina.OpenEJBValve","methodName":"invoke","fileName":"OpenEJBValve.java","lineNumber":44},{"declaringClass":"org.apache.catalina.authenticator.AuthenticatorBase","methodName":"invoke","fileName":"AuthenticatorBase.java","lineNumber":522},{"declaringClass":"org.apache.catalina.core.StandardHostValve","methodName":"invoke","fileName":"StandardHostValve.java","lineNumber":140},{"declaringClass":"org.apache.catalina.valves.ErrorReportValve","methodName":"invoke","fileName":"ErrorReportValve.java","lineNumber":79},{"declaringClass":"org.apache.catalina.valves.AbstractAccessLogValve","methodName":"invoke","fileName":"AbstractAccessLogValve.java","lineNumber":620},{"declaringClass":"org.apache.catalina.core.StandardEngineValve","methodName":"invoke","fileName":"StandardEngineValve.java","lineNumber":87},{"declaringClass":"org.apache.catalina.connector.CoyoteAdapter","methodName":"service","fileName":"CoyoteAdapter.java","lineNumber":349},{"declaringClass":"org.apache.coyote.ajp.AjpProcessor","methodName":"service","fileName":"AjpProcessor.java","lineNumber":780},{"declaringClass":"org.apache.coyote.AbstractProcessorLight","methodName":"process","fileName":"AbstractProcessorLight.java","lineNumber":66},{"declaringClass":"org.apache.coyote.AbstractProtocol$ConnectionHandler","methodName":"process","fileName":"AbstractProtocol.java","lineNumber":785},{"declaringClass":"org.apache.tomcat.util.net.NioEndpoint$SocketProcessor","methodName":"doRun","fileName":"NioEndpoint.java","lineNumber":1425},{"declaringClass":"org.apache.tomcat.util.net.SocketProcessorBase","methodName":"run","fileName":"SocketProcessorBase.java","lineNumber":52},{"declaringClass":"java.util.concurrent.ThreadPoolExecutor","methodName":"runWorker","fileName":"ThreadPoolExecutor.java","lineNumber":1142},{"declaringClass":"java.util.concurrent.ThreadPoolExecutor$Worker","methodName":"run","fileName":"ThreadPoolExecutor.java","lineNumber":617},{"declaringClass":"org.apache.tomcat.util.threads.TaskThread$WrappingRunnable","methodName":"run","fileName":"TaskThread.java","lineNumber":61},{"declaringClass":"java.lang.Thread","methodName":"run","fileName":"Thread.java","lineNumber":745}],"suppressedExceptions":[]},"stackTrace":[{"declaringClass":"com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter","methodName":"read","fileName":"ReflectiveTypeAdapterFactory.java","lineNumber":224},{"declaringClass":"com.google.gson.Gson","methodName":"fromJson","fileName":"Gson.java","lineNumber":887},{"declaringClass":"com.google.gson.Gson","methodName":"fromJson","fileName":"Gson.java","lineNumber":852},{"declaringClass":"com.teamdae.common.arch.jax.handler.GsonMessageBodyHandler","methodName":"readFrom","fileName":"GsonMessageBodyHandler.java","lineNumber":91},{"declaringClass":"org.apache.cxf.jaxrs.utils.JAXRSUtils","methodName":"readFromMessageBodyReader","fileName":"JAXRSUtils.java","lineNumber":1342},{"declaringClass":"org.apache.cxf.jaxrs.utils.JAXRSUtils","methodName":"readFromMessageBody","fileName":"JAXRSUtils.java","lineNumber":1293},{"declaringClass":"org.apache.cxf.jaxrs.utils.JAXRSUtils","methodName":"processParameter","fileName":"JAXRSUtils.java","lineNumber":826},{"declaringClass":"org.apache.cxf.jaxrs.utils.JAXRSUtils","methodName":"processParameters","fileName":"JAXRSUtils.java","lineNumber":789},{"declaringClass":"org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor","methodName":"processRequest","fileName":"JAXRSInInterceptor.java","lineNumber":212},{"declaringClass":"org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor","methodName":"handleMessage","fileName":"JAXRSInInterceptor.java","lineNumber":77},{"declaringClass":"org.apache.cxf.phase.PhaseInterceptorChain","methodName":"doIntercept","fileName":"PhaseInterceptorChain.java","lineNumber":308},{"declaringClass":"org.apache.cxf.transport.ChainInitiationObserver","methodName":"onMessage","fileName":"ChainInitiationObserver.java","lineNumber":121},{"declaringClass":"org.apache.cxf.transport.http.AbstractHTTPDestination","methodName":"invoke","fileName":"AbstractHTTPDestination.java","lineNumber":254},{"declaringClass":"org.apache.openejb.server.cxf.rs.CxfRsHttpListener","methodName":"doInvoke","fileName":"CxfRsHttpListener.java","lineNumber":251},{"declaringClass":"org.apache.tomee.webservices.CXFJAXRSFilter","methodName":"doFilter","fileName":"CXFJAXRSFilter.java","lineNumber":94},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"internalDoFilter","fileName":"ApplicationFilterChain.java","lineNumber":192},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"doFilter","fileName":"ApplicationFilterChain.java","lineNumber":165},{"declaringClass":"org.apache.tomcat.websocket.server.WsFilter","methodName":"doFilter","fileName":"WsFilter.java","lineNumber":52},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"internalDoFilter","fileName":"ApplicationFilterChain.java","lineNumber":192},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"doFilter","fileName":"ApplicationFilterChain.java","lineNumber":165},{"declaringClass":"org.apache.catalina.filters.HttpHeaderSecurityFilter","methodName":"doFilter","fileName":"HttpHeaderSecurityFilter.java","lineNumber":120},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"internalDoFilter","fileName":"ApplicationFilterChain.java","lineNumber":192},{"declaringClass":"org.apache.catalina.core.ApplicationFilterChain","methodName":"doFilter","fileName":"ApplicationFilterChain.java","lineNumber":165},{"declaringClass":"org.apache.catalina.core.StandardWrapperValve","methodName":"invoke","fileName":"StandardWrapperValve.java","lineNumber":198},{"declaringClass":"org.apache.catalina.core.StandardContextValve","methodName":"invoke","fileName":"StandardContextValve.java","lineNumber":108},{"declaringClass":"org.apache.tomee.catalina.OpenEJBValve","methodName":"invoke","fileName":"OpenEJBValve.java","lineNumber":44},{"declaringClass":"org.apache.catalina.authenticator.AuthenticatorBase","methodName":"invoke","fileName":"AuthenticatorBase.java","lineNumber":522},{"declaringClass":"org.apache.catalina.core.StandardHostValve","methodName":"invoke","fileName":"StandardHostValve.java","lineNumber":140},{"declaringClass":"org.apache.catalina.valves.ErrorReportValve","methodName":"invoke","fileName":"ErrorReportValve.java","lineNumber":79},{"declaringClass":"org.apache.catalina.valves.AbstractAccessLogValve","methodName":"invoke","fileName":"AbstractAccessLogValve.java","lineNumber":620},{"declaringClass":"org.apache.catalina.core.StandardEngineValve","methodName":"invoke","fileName":"StandardEngineValve.java","lineNumber":87},{"declaringClass":"org.apache.catalina.connector.CoyoteAdapter","methodName":"service","fileName":"CoyoteAdapter.java","lineNumber":349},{"declaringClass":"org.apache.coyote.ajp.AjpProcessor","methodName":"service","fileName":"AjpProcessor.java","lineNumber":780},{"declaringClass":"org.apache.coyote.AbstractProcessorLight","methodName":"process","fileName":"AbstractProcessorLight.java","lineNumber":66},{"declaringClass":"org.apache.coyote.AbstractProtocol$ConnectionHandler","methodName":"process","fileName":"AbstractProtocol.java","lineNumber":785},{"declaringClass":"org.apache.tomcat.util.net.NioEndpoint$SocketProcessor","methodName":"doRun","fileName":"NioEndpoint.java","lineNumber":1425},{"declaringClass":"org.apache.tomcat.util.net.SocketProcessorBase","methodName":"run","fileName":"SocketProcessorBase.java","lineNumber":52},{"declaringClass":"java.util.concurrent.ThreadPoolExecutor","methodName":"runWorker","fileName":"ThreadPoolExecutor.java","lineNumber":1142},{"declaringClass":"java.util.concurrent.ThreadPoolExecutor$Worker","methodName":"run","fileName":"ThreadPoolExecutor.java","lineNumber":617},{"declaringClass":"org.apache.tomcat.util.threads.TaskThread$WrappingRunnable","methodName":"run","fileName":"TaskThread.java","lineNumber":61},{"declaringClass":"java.lang.Thread","methodName":"run","fileName":"Thread.java","lineNumber":745}],"suppressedExceptions":[]}}}
1

My guess is that it is because you don't have your data (payload) quoted well:

>echo {"username":"TheUserName"} 
{username:TheUserName}

Note that double quotes have disappeared, after the shell processed them.

And AFAIK JSON does not allow for unquoted strings.

To fix this, just put a pair of single quotes around your data, like this:

>echo '{"username":"TheUserName"}'
{"username":"TheUserName"}

If you want shell expansion (variable substitution) to work inside your data, use double quotes and escape the inner quotes:

>echo "{\"username\":\"$username\"}"
{"username":"myuser"}

Please note that there are more ways to properly quote your shell arguments (I believe, there is a bunch of good answers on this site about it already). And you can also put your data in a file instead, if you wish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.