Home Man
Search
Today's Posts
Register

Tutorials for how to post and interact in the forums.

Read a json file passed as cmd line argument

Tags
json, linux, shell script

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 06-26-2017
Read a json file passed as cmd line argument

usage: myscript.sh config.json

config.json:

Code:
{
   "HOST":"abc",
   "DB_NM":"xyz",
   "USR_NM":"asd",
   "PWD":"xxx",
    .........
    .........
    .........
    ........
}

myscript.sh:
Code:

    #HOW TO SOURCE THE config.json file? 
    I would like to use the variables in config.josn file to prepare a query and execute in Linux Shell as show below. 

    host=$HOST/$DB_NM
    usr_nm="--username $USR_NM"
    pwd="--password $PWD"

    query= "--connect $host $usr_nm $pwd"
    eval $query

I am new to shell scripting. Please help me on this.

Last edited by RGRT; 06-29-2017 at 02:22 PM.. Reason: Update
# 2  
Old 06-26-2017
see if that helps:
Code:
awk -F '("|:)' 'NF>1 {print $2,$5}' config.json

# 3  
Old 06-27-2017
I'm afraid there quite some open questions, like
- which combinations from that config file entries do you need,all permutations from the 10 - 15 entries?
- which section of the file should be used, or is there just one?
- how are you going to use the results, source them in myscript.sh?
- are you sure the host part and the DB part will be joined by a / ?
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting number of argument passed to a shell script mukulverma2408 Shell Programming and Scripting 4 09-13-2017 11:54 AM
Perl Code to change file delimiter (passed as argument) to bar delimiter JPB1977 Shell Programming and Scripting 2 01-05-2014 09:23 AM
Variable passed as argument anil510 Shell Programming and Scripting 3 03-03-2013 04:02 AM
Shell script that check the argument passed to it and prints error if test condition is not met mukulverma2408 Shell Programming and Scripting 3 07-20-2012 09:50 AM
shell script for ftp files passed in command line argument rateeshkumar Shell Programming and Scripting 5 03-23-2011 10:27 PM
Read env variables from argument file bOngY Shell Programming and Scripting 10 12-24-2010 08:46 AM
File not recognized when passed as argument michaelrozar17 Shell Programming and Scripting 9 08-14-2010 02:17 AM
bash: read file line by line (lines have '\0') - not full line has read??? alex_5161 Shell Programming and Scripting 6 04-14-2010 04:58 AM
how to print all argument passed RahulJoshi Shell Programming and Scripting 2 10-13-2008 05:38 PM
Check if argument passed is an integers elchalateco Shell Programming and Scripting 13 11-07-2002 08:23 AM


All times are GMT -4. The time now is 08:45 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password