LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-07-2014, 02:51 PM   #1
Yow
LQ Newbie
 
Registered: May 2010
Posts: 5

Rep: Reputation: 0
How to insert Dynamic UUID and Date into Curl command


Firstly, I apologize if this sounds like an easy question but I'm new to Curl. I used the command below on an ecommerce system to obtain a Publickey, and it works when I manually put a UUID value in the Stars shown in the code below.

curl -k -i -H "Content-Type: application/json" -H "X-HTTP-Method-Override: PUT" -X POST -d '{"applicationId":"system1","tranDateTime":"***********","UUID":"**************"}' 'ht*ps://192.168.101.200:1245/HermesSim/getPublicKey'

What I need to do is to run the command but instead of a fixed UUID value, I'd like to save the above command in a script and use the "UUID" command or "GENUUID" command to generate the Unique UUID value dynamically each time the script is executed, also the tranDateTime field should be filled with the Date command to record the current date for that transaction. I tried a number of ways to insert the commands in the field but it always takes the command as a string and therefor I send a wrong UUID or Date.

Can I do that with curl? or is there an easier or better way to do it?

We've tried to do it in PHP before, but we've encountered problems and we figured if we do it using this script then in PHP we can run the script and take the output from it back to PHP.
 
Old 08-08-2014, 02:05 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Quote:
Originally Posted by Yow View Post
I tried a number of ways to insert the commands in the field but it always takes the command as a string
Instead of talking about what you've done please post what you've actually tried.
 
Old 08-08-2014, 06:52 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Your problem is caused by making the command line too complex with the quoting.

Do it in steps rather than all in one.

Code:
'{"applicationId":"system1","tranDateTime":"***********","UUID":"**************"}' 'ht*ps://192.168.101.200:1245/HermesSim/getPublicKey'
Is a real pain with the quoting.

Code:
UUID="whatever it is supposed to be"
pt1='{"applicationId":"system1","tranDateTime":"***********","'
pt2='":"**************"}'
res="${p1}${UUID}${p2}"
curl -k -i -H "Content-Type: application/json" -H "X-HTTP-Method-Override: PUT" -X POST -d "${res}"
Should work. This is because quotes are only evaluated once during the assignment so the nested quoting doesn't cause a problem.

The problem is cause by using apostrophe quotes needed to avoid the awkward escaping that would be required for the embedded double quotes... The apostrophe disables substitution within the string.

Doing it in parts (as shown) helps simplify the quoting, and allows you to test things as it goes.
 
Old 08-09-2014, 03:42 AM   #4
Yow
LQ Newbie
 
Registered: May 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks a lot jpollard!!
That helped a lot, very simple and clear! I don't know how I haven't thought of that.

As you said, this way it'll make it easier to test as I go instead of combining things at once. It:s better to break it down and go in pieces.

Thanks again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Date timestamp from .gz files. liketheshell Linux - Newbie 2 09-25-2012 09:44 PM
Change UUID - Edit UUID using the dd command GMHilltop Linux - Newbie 10 10-28-2010 08:39 PM
Using wget or curl command to download from dynamic urls pratap.iisc Linux - Desktop 2 07-26-2009 11:55 PM
Insert date and timestamp Into File name petenyce Linux - Newbie 9 10-13-2005 01:16 PM
Get the date on PHP and insert it into SQL poeta_boy Programming 4 11-26-2003 04:25 AM


All times are GMT -5. The time now is 06:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration