Bash variable to Curl
Good Afternoon Everyone,
I am having an issue with a bash script and getting the variables into CURL. I have combed the internet and just can't seem to get it to work. I have a website that I need to pull a log file from for a week timeframe. Code:
#!/bin/bash One of the examples I have found that I can't seem to get to work is as follows: Code:
curl --data "$(printf 'StartDate=%q&EndDate=%q&xmlfile=xmlfile' "$StartDate" "$EndDate")" |
Try putting set -xv near the top.
Running it myself, I get this: Code:
+ curl --data 'StartDate=Tue Aug 8 14:34:08 PDT 2017&EndDate=Thu Aug 3 14:34:08 PDT 2017&xmlfile=xml' Quote:
|
Welcome to LQ!
Quote:
|
I agree with the others that the default output format from the date command is not what is expected by the web page. Basically --data "StartDate=${StartDate}&EndDate=${EndDate}&xmlfile=xml" is filling out the form as if you actually were entering it using your web browser. The date formats must match. In addition the data needs to be properly encoded i.e If any spaces are required you need to replace them with a %20.
https://curl.haxx.se/docs/httpscript...orms_explained |
I apologize. I need to revise my original post.
Code:
#!/bin/bash |
The answer is exactly what you posted.
|
So then we know it's not a formatting issue.
|
It is a formatting issue. And probably something else too. But first you need to fix that formatting, so you need to replace the 2 lines in your script to the two lines from post #5 (StartDate=... and EndDate=...)
|
Code:
|
I don't know what do you mean by that.
Probably you need to swap start and end |
so I revised my code a little bit. thank you for telling me to type set -xv up at the top. Here's my code now and the result of what's being sent.
Code:
#!/bin/bash Code:
curl --data 'StartDate=08-09-17&EndDate=08-04-17&xmlfile=xmlfile' Code:
<log> and here's the portion of the site I'm trying to interface with: Code:
<input name="StartDate" value="08/10/2017" size="15"> |
Quote:
|
Code:
#!/bin/bash |
Quote:
So, if that works, but this doesn't... Code:
curl --data 'StartDate=08-09-17&EndDate=08-04-17&xmlfile=xmlfile' It is probably a matter that the target script is very picky about what you send to it. |
so now I have the following
Code:
#!/bin/bash this is the result: Code:
curl --data 'StartDate=08/09/17&EndDate=08/04/17&xmlfile=xmlfile' |
All times are GMT -5. The time now is 07:08 PM. |