简体   繁体   English

从shell脚本执行curl

[英]Executing curl from a shell script

How can I invoke curl command correctly from a shell script? 如何从Shell脚本正确调用curl命令?

I have a script that actually works in one environment but doesn't on other: 我有一个脚本实际上可以在一种环境中工作,但不能在其他环境中工作:

I've researched a lot but still don't know what the problem is, it has to be related to fact that I'm trying to send a date time parameter that contains a space (which i have replaced by a %20). 我已经进行了很多研究,但仍然不知道问题出在哪里,它与我试图发送包含空格的日期时间参数(我已将其替换为%20)有关。 The shell runs without errors but it is not reaching the URL (I can tell that because I see no activity on the destination service) Shell运行时没有错误,但是没有到达URL(我可以说是因为我看不到目标服务上的任何活动)

dateTo=$(date +"%Y-%m-%d%%20%H:%M:%S")
dateFrom=$(date --date='8 hour ago' +"%Y-%m-%d%%20%H:%M:%S")

/usr/bin/curl -k "https://aurl.com/JobHandlerWeb/JobSchedulerServlet?jobId=2&busSvcId=1&receivedFromDate=$dateFrom&receivedToDate=$dateTo"

I found the issue: file format problem. 我发现了问题:文件格式问题。

I had created the file under Windows, and that was making all the difference. 我已经在Windows下创建了文件,这一切都与众不同。 Even though I thought it was the same script running fine in one environment, the file format (end line characters) were different. 即使我认为同一脚本可以在一个环境中正常运行,但文件格式(结束行字符)却有所不同。

Corrected using Notepadd++ --> Edit --> EOL conversion 使用Notepadd ++进行了更正->编辑-> EOL转换

Thanks for your help attempts 感谢您的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM