Help With Json Code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help With Json Code
# 1  
Old 11-30-2016
Help With Json Code

Hello Experts,

I have written a code to bootstrap my application and it is failing becasue it is not executing as expected. Command is as follows in my json template,

Code:
"UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
      "#!/bin/bash -v\n",
      "apt-get upgrade -y\n",

      "# Install packages\n",
      "/usr/bin/cloud-init -s ", { "Ref" : "AWS::StackName" },
	  "    --region ", { "Ref" : "AWS::Region" }, 

             "# Install the Application and packages from the metadata\n",
             "sudo sh /var/www/html/app/bin/setupscript \n", 
			 "-u", {"Ref" : "URL"},
			 "-f", {"Ref" : "FirstName"},
			 "-l", {"Ref" : "LastName"}, 
			 "-e", {"Ref" : "Email"}, 
			 "-p", {"Ref" : "Password"},
			 "-c", {"Ref" : "CountryCode"}, 
			 "-s", {"Ref" : "StateCode"}, 
			 "-t", {"Ref" : "City"},
			 "-o", {"Ref" : "OrgName"}, 
			 "-r", {"Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}, 
			 "-d", {"Ref" : "DBName"}, 
			 "-a", {"Ref" : "DBUser"}, 
			 "-b", {"Ref" : "DBPassword"},
			 "-h", { "Fn::GetAtt" : [ "DBInstance", "Endpoint.Address" ] }			 
		]]}}

Now it does execute but not as expected. This is what i get in the backend,

Code:
root@ip-10-0-1-252:/var/lib/cloud/instance# cat user-data.txt
#!/bin/bash -v
apt-get upgrade -y# Install packages
/usr/bin/cloud-init -s Stack    --region us-west-2# Install the Application and packages from the metadata
sudo sh /var/www/html/app/bin/install
-uhttp://test.example.com-fSiddhesh-lKhavnekar-es.khavnekar@gmail.com-pmagento123-cIndia-sMaharashtra-tMumbai-oTestReseller-rMagentoSt-ElasticL-15OYLTVSLF4GR-1502451718.us-west-2.elb.amazonaws.com-dmagentodb-amagento-bmagento123-hmd1tt96j81juryu.cvjxzqrkxoho.us-west-2.rds.amazonaws.comroot@ip-10-0-1-252:/var/lib/cloud/instance#

There has to be space between each parameters and the value mentioed shoudl be in quotes. So the right command should be as below,

Code:
root@ip-10-0-1-252:/var/lib/cloud/instance# cat user-data.txt
#!/bin/bash -v
apt-get upgrade -y# Install packages
/usr/bin/cloud-init -s Stack    --region us-west-2# Install the Application and packages from the metadata
sudo sh /var/www/html/app/bin/install -u "http://test.example.com" -f "Siddhesh" -l "Khavnekar" -e "s.khavnekar@gmail.com" -p "magento123" -c "India" -s "Maharashtra" -t "Mumbai" -o "TestReseller" -r "MagentoSt-ElasticL-15OYLTVSLF4GR-1502451718.us-west-2.elb.amazonaws.com" -d "magentodb" -a "magento" -b "magento123" -h "md1tt96j81juryu.cvjxzqrkxoho.us-west-2.rds.amazonaws.com"

Any help would be appreciated. Thanks.

Last edited by rbatte1; 12-01-2016 at 05:06 AM.. Reason: Changed HTML tags to CODE tags
# 2  
Old 12-01-2016
This is a simple case of string concatenation.
For e.g., in your json, instead of "-u", you could try using "-u "
Similarly, you could concatenate URL with double quote before and after it.
# 3  
Old 12-01-2016
Hi,

Thanks for the reply. Adding space before and after fixed one part but i want the corresponding value in double quotes. With the suggested change my script looks like this,

HTML Code:
sudo ./setupscript -u http://www.test.sid.com -f Test -l RTM-5 -e s.khavnekar@gmail.com -p 12345qwer -c US -s CA -t IRVINE -o TestCustomer -r ec2-35-164-172-109.us-west-2.compute.amazonaws.com -d magentodb -a magento -b magento123 -h magentodb.cvjxzqrkxoho.us-west-2.rds.amazonaws.com
expected output is

HTML Code:
sudo ./setupscript -u "http://www.test.sid.com" -f "Test" -l "RTM-5" -e "s.khavnekar@gmail.com" -p "12345qwer" -c "US" -s "CA" -t "IRVINE" -o "TestCustomer" -r "ec2-35-164-172-109.us-west-2.compute.amazonaws.com" -d "magentodb" -a "magento" -b "magento123" -h "magentodb.cvjxzqrkxoho.us-west-2.rds.amazonaws.com"
This is what my json code looks like now,

HTML Code:
"sudo sh /var/www/html/app/bin/setupscript \n", 
			 " -u ", {"Ref" : "URL"},
			 " -f ", {"Ref" : "FirstName"},
			 " -l ", {"Ref" : "LastName"}, 
			 " -e ", {"Ref" : "Email"}, 
			 " -p ", {"Ref" : "Password"},
			 " -c ", {"Ref" : "CountryCode"}, 
			 " -s ", {"Ref" : "StateCode"}, 
			 " -t ", {"Ref" : "City"},
			 " -o ", {"Ref" : "OrgName"}, 
			 " -r ", {"Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}, 
			 " -d ", {"Ref" : "DBName"}, 
			 " -a ", {"Ref" : "DBUser"}, 
			 " -b ", {"Ref" : "DBPassword"},
			 " -h ", { "Fn::GetAtt" : [ "DBInstance", "Endpoint.Address" ] }			
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Parse property from json file

Hello All, Greetings.. I have a json file that I need to pase its URLs and other values. The match should start with "notifications" and output URLs and settings values. I tried with python or awk but hardly could get URLs only. Or whole URLs from full json file. Could not match... (2 Replies)
Discussion started by: 7adi
2 Replies

2. Shell Programming and Scripting

JSON Output format

Dear friends, I'm getting below API result and i would like to format them with Shell scripting. Input "id": 9, "description": "short desc", "name": "test", "name_with_namespace": "ABCD-PDFF-PLATFORM-TEST-V1 / test", "path": "test", "path_with_namespace":... (7 Replies)
Discussion started by: baluchen
7 Replies

3. Shell Programming and Scripting

Convert json to xml

Hello everyone, I have created a workflow that will pull down data via a RESTful API in JSON, then my code parses and modifies said data. The problem I have is that these APIs I am working with only accept XML to PUT/POST data, and I am looking for an easy way to convert my JSON file to XML. ... (2 Replies)
Discussion started by: Zaphod_B
2 Replies

4. Programming

Perl array / json

Hi All I have used the below code to print the dumper of a json #!/usr/bin/perl use LWP::Simple; use JSON qw( decode_json ); use Data::Dumper; use strict; use warnings; my (%list); my $trendsurl =... (5 Replies)
Discussion started by: ab52
5 Replies

5. Programming

Perl Json and Hash

Hi all, i am using the following code to that use curl to that outputs a json, i am stuck it into a hash but i canot figure out how to get just the value i need ( hostname) here is my code use warnings; use strict; use Data::Dumper qw(Dumper); ##use JSON; use JSON::XS; my $curl=... (2 Replies)
Discussion started by: ab52
2 Replies

6. Programming

Json dissect with python

hello, I'm trying to parse a json file and print out each element along with some related infos such type and value. I would like to do that in python and I found a nice support to quickly load the json file, instead I found a bit more difficult the information extraction. Example, I have... (0 Replies)
Discussion started by: Dedalus
0 Replies

7. Shell Programming and Scripting

perl code-sequence of json format

Hi All , Below is the perl code. from below code want to confirm one thing that wahtever the sequence of data we are passing through json format which contains 3 tuples of different sequences Eg: ParentID,SystemID,SendingTime,Time,ClientLocation,ClientID, ... (1 Reply)
Discussion started by: aish11
1 Replies
Login or Register to Ask a Question