Find the answer to your Linux question:
Results 1 to 7 of 7
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Date Variable passed to curl

    Hello Everyone,

    I have a script that goes and gets an xml file from a website using curl. The xml file requires that I get a time frame of 1 week. Here is what I have so far
    lstwk=$'(date -d 6 days ago)'
    curl --data "StartDate=$date&EndDate="${lstw}"&xmlfile=xmlfile"
    The result I keep getting is that the equation for the variable lstwk is getting passed through to the curl instead of date from 6 days ago being passed through.

    How do I get the result of date -d "6 days ago" to be attached to the variable lstwk?

    Thank you in advance!

  2. #2
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris

    I modified your script snippet as follows:"
    $ cat -n z8
         1  date=$date
         2  lstwk=$'(date -d 6 days ago)'
         3  v1=$'(date -d 6 days ago)'
         4  echo " v1 = :$v1:"
         5  v2=$( date -d "6 days ago" )
         6  echo " v2 = :$v2:"
         8  # curl --data "StartDate=$date&EndDate="${lstw}"&xmlfile=xmlfile"
         9  echo curl --data "StartDate=$date&EndDate="${lstw}"&xmlfile=xmlfile"
        10  echo
        11  echo curl --data "StartDate=$date&EndDate=${lstw}&xmlfile=xmlfile"
    I then ran program shellcheck over it, producing in part:
    $ shellcheck z8
    In z8 line 2:
    lstwk=$'(date -d 6 days ago)'
    ^-- SC2034: lstwk appears unused. Verify it or export it.
    and finally ran it with bash, producing:
    $ bash z8
     v1 = :(date -d 6 days ago):
     v2 = :Sun Jul 30 10:26:31 CDT 2017:
    curl --data StartDate=&EndDate=&xmlfile=xmlfile
    curl --data StartDate=&EndDate=&xmlfile=xmlfile
    What would we learn from this about:
    1) Your script,
    2) Debugging

    If you are interested, here are some details on shellcheck:
    shellcheck      analyse shell scripts (man)
    Path    : /usr/bin/shellcheck
    Version : 0.3.4
    Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)
    Help    : probably available with -h
    Repo    : Debian 8.8 (jessie) 
    Home    : (pm)
    This was on a system like:
    OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
    Distribution        : Debian 8.8 (jessie) 
    bash GNU bash 4.3.30
    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Linux Guru
    Join Date
    Dec 2013
    ^ in other words, there's a typo in your script.
    and after fixing that, it still might have issues; how do we know what sort of format the site requires, and what sort of string your command provides, and if that string can be passed to curl in that manner?

    debug & troubleshoot...

  4. $spacer_open
  5. #4
    Thanks for the help. I think I know where the problem is but I still need some help with this.

    the proper way to get 6 days ago is like this

    date -d "6 days ago"
    The problem that I'm having is that the variable lstwk isn't returning a value to pass through to curl. What I have tried is the following:

    lstwk=$'(date -d "6 days ago")'
    and what I get as a return value when when I try to run the variable is
    echo $lstwk
    (date -d "6 days ago")
    So I tried this to make sure it's a quotation issue is this
    lstwk=$(date -d "6 days ago")
    echo $lstwk
    TUE AUG 1 10:23:37
    So I know the issue is that I'm trying to pass it through, but it's passing through the equation not result. Is there a way to copy the value of the echo and pass that through?
    Last edited by Ethaniz3d; 08-07-2017 at 05:26 PM. Reason: typo

  6. #5
    Linux Guru
    Join Date
    Dec 2013
    i'm sorry you lost me there.
    isn't the last variant what you want?

    btw, are you aware of the difference between double and single quotes in bash scripting?

  7. #6
    I kind of know the difference but not entirely.
    I do want the value of that last variant but I need the value of the last variant to be passed to the curl script instead of the (date -d "6 days ago"). I need the date, not the code.

  8. #7
    Linux Guru
    Join Date
    Dec 2013
    ^ but that is exactly what will happen if you use that last variant.

    have you shown us the entire script, or are there some other limitations we might be unaware of?

    and please start reading some bash tutorials, there's a lot to choose from, the official:
    and many others, e.g.:
    EnglishFrontPage - Greg's Wiki

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts