Shellscript 卷曲给出错误

Shellscript 卷曲给出错误

我正在尝试使用curl 创建一个小shellscript。

这是脚本(我需要隐藏用户名、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

现在当我运行这个我有这个错误:

{"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

我的猜测是,这是因为你没有很好地引用你的数据(有效负载):

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

请注意,双引号在 shell 处理后消失了。

并且 AFAIK JSON 不允许使用不带引号的字符串。

为了解决这个问题,只需在数据周围加上一对单引号,如下所示:

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

如果您希望 shell 扩展(变量替换)在数据中起作用,请使用双引号并转义内部引号:

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

请注意,有更多方法可以正确引用您的 shell 参数(我相信,这个网站上已经有很多关于它的很好的答案)。如果您愿意,您也可以将数据放入文件中。

相关内容