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
    Code:
    date=$date
    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
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,461
    Hi.

    I modified your script snippet as follows:"
    Code:
    $ 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:"
         7
         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:
    Code:
    $ 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:
    Code:
    $ 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:
    Code:
    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    : http://hackage.haskell.org/package/ShellCheck (pm)
    This was on a system like:
    Code:
    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
    ^ 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...
    I am not a "Linux Guru"! Get off me! The Forum software won't let me change it!
    How to ask smart questions | Don't be a Help Vampire | How to Use Code Tags
    You can post a link by removing "http://www." from it.

  4. $spacer_open
    $spacer_close
  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

    Code:
    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:

    Code:
    lstwk=$'(date -d "6 days ago")'
    and what I get as a return value when when I try to run the variable is
    Code:
    echo $lstwk
    (date -d "6 days ago")
    So I tried this to make sure it's a quotation issue is this
    Code:
    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
    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?
    I am not a "Linux Guru"! Get off me! The Forum software won't let me change it!
    How to ask smart questions | Don't be a Help Vampire | How to Use Code Tags
    You can post a link by removing "http://www." from it.

  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
    ^ 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:
    https://www.gnu.org/software/bash/manual/
    and many others, e.g.:
    EnglishFrontPage - Greg's Wiki
    https://bash.cyberciti.biz/guide/Main_Page
    ...etc...
    I am not a "Linux Guru"! Get off me! The Forum software won't let me change it!
    How to ask smart questions | Don't be a Help Vampire | How to Use Code Tags
    You can post a link by removing "http://www." from it.

Posting Permissions

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