Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to convert any shell command output to JSON format? Post 303037795 by balu1234 on Tuesday 13th of August 2019 05:11:45 PM
Old 08-13-2019
How to convert any shell command output to JSON format?

Hi All,

I am new to shell scripting, Need your help in creating a shell script which converts any unix command output to JSON format output.
example:
sample df -h command ouput :

Code:
Filesystem   size   used   avail   capacity   Mounted
/dev/dsk/c1t0d0s0   8.1G   4.0G   4.0G   50%   /
/devices   0K   0K   0K   0%   /devices
ctfs   0K   0K   0K   0%   /system/contract
proc   0K   0K   0K   0%   /proc
mnttab   0K   0K   0K   0%   /etc/mnttab
swap   3.1G   836K   3.1G   1%   /etc/svc/volatile
objfs   0K   0K   0K   0%   /system/object
sharefs   0K   0K   0K   0%   /etc/dfs/sharetab
/usr/lib/libc/libc_hwcap1.so.1   8.1G   4.0G   4.0G   50%   /lib/libc.so.1
fd   0K   0K   0K   0%   /dev/fd
swap   3.1G   84K   3.1G   1%   /tmp
swap   3.1G   32K   3.1G   1%   /var/run
/dev/dsk/c1t0d0s7   11G   11M   11G   1%   /export/home
/vol/dev/dsk/c0t0d0/sol_10_113_x86   2.1G   2.1G   0K   100%   /cdrom/sol_10_113_x86

Desired output in JSON format:

Code:
{
"Filesystem": "/dev/dsk/c1t0d0s0",
"size": "8.1G",
"used": "4.0G",
"avail": "4.0G"
"capacity": "50%",
"Mounted": "/"
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script to format command output

Hello team, I am running below command which is giving following output. bash-3.00$ ps -eo pid,pcpu,args | sort +1n | grep -i java 12 0.0 grep -i java 8804 0.0 /opt/app/ccr/home/ccr/WebSphere/AppServer/java/bin/sparcv9/java -XX:+UnlockDiag 9241 0.0... (7 Replies)
Discussion started by: coolguyamy
7 Replies

2. Shell Programming and Scripting

convert the output in table format

Hi All, I have a output like below values val1=test.com val2=10.26.208.11 val3=en1 val4=test-priv1.com val5=192.168.3.4 val6=en2 val7=test-priv2.com val8=192.168.4.4 val9=en3 val10=test-vip.com val11=10.26.208.9 val12=$val3 I want to convet this output values into below... (1 Reply)
Discussion started by: kamauv234
1 Replies

3. Shell Programming and Scripting

Convert TZ output to a different format

Friends, I am trying to convert my local server timezone EST to UTC and for which I used the TZ command, see below $ date Thu Dec 6 10:14:14 EST 2012 $ $ TZ=UTC date -d '10:14 EST' Thu Dec 6 15:14:00 UTC 2012 Now I would like to have the same output in 'yyyymmdd hh:mm' format. ... (4 Replies)
Discussion started by: vivek_damodaran
4 Replies

4. Shell Programming and Scripting

Multiple records need to convert UNIXtime to human readable datatime and all output in one format

Hello Experts, Below is the record i have: sample data attached I want this record of each row to be in single line and there are multiple rowise unixtime mentioned e.g 11996327 , This needs to be converted to Human readdable data and time from multiple rows Can you help me , it will be... (10 Replies)
Discussion started by: manishK
10 Replies

5. 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

6. Shell Programming and Scripting

Loop to convert text output in the HTML format

Hello Everyone, I have a sample file raw.txt as shown below : Drive Bays Bay Name : SD-2C Number of Standby Power Supplies : 4 Number of Drive Enclosures : 12 Summary Status of Contained Modules All... (6 Replies)
Discussion started by: rahul2662
6 Replies

7. 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

8. UNIX for Beginners Questions & Answers

Convert rows to column and print output in required format

Hi All, i am trying to print the solaris 11 packages in below required format, But i am unable to do that. Current ouput : root@abc# pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' NAME: QLogic 570x/571x Gigabit Ethernet Driver VERSION: 11.11,REV=2009.11.11 ... (7 Replies)
Discussion started by: balu1234
7 Replies

9. UNIX for Beginners Questions & Answers

Convert String to an Array using shell scripting in JSON file.

This is the sample json I have pasted here. I want all the IP address strings to be converted into an array. For example "10.38.32.202" has to be converted to everywhere in the JSON. There are multiple IPs in a JSON I am pasting one sample object from the JSON. But the IPs already in an Array... (11 Replies)
Discussion started by: vinshas1
11 Replies

10. UNIX for Beginners Questions & Answers

Printing df -h output in json format

Hi All, i am trying to print the df -h ouput in json format. using below script. #!/usr/bin/env bash df -h > /tmp/sdf nawk '{print " "$1" "$2" "$3" "$4" "$5" "$6" "}' /tmp/sdf > /tmp/sdf1 nawk 'NR==1 { for (i=1; i<=NF; i++) { f = i }}{ print $(f), $(f), $(f), $(f), ... (2 Replies)
Discussion started by: sravani25
2 Replies
lufslist(1M)															      lufslist(1M)

NAME
lufslist - list configuration of a boot environment SYNOPSIS
/usr/sbin/lufslist [-l error_log] [-o outfile] BE_name [-X] DESCRIPTION
The lufslist command is part of a suite of commands that make up the Live Upgrade feature of the Solaris operating environment. See live_upgrade(5) for a description of the Live Upgrade feature. The lufslist command lists the configuration of a boot environment (BE). The output contains the disk slice (file system), file system type, and file system size for each BE mount point. The following is an example of lufslist output. # lufslist BE_name Filesystem fstype size(Mb) Mounted on ------------------------------------------------------------------ /dev/dsk/c0t0d0s1 swap 512.11 - /dev/dsk/c0t4d0s3 ufs 3738.29 / /dev/dsk/c0t4d0s4 ufs 510.24 /opt File system type can be ufs, swap, or vxfs, for a Veritas file system. Under the Filesystem heading can be a disk slice or a logical device, such as a disk metadevice used by volume management software. The lufslist command requires root privileges. OPTIONS
The lufslist command has the following options: -l error_log Error and status messages are sent to error_log, in addition to where they are sent in your current environment. -o outfile All command output is sent to outfile, in addition to where it is sent in your current environment. -X Enable XML output. Characteristics of XML are defined in DTD, in /usr/share/lib/xml/dtd/lu_cli.dtd.<num>, where <num> is the version number of the DTD file. OPERANDS
BE_name Name of the BE for which file systems are to be reported. You cannot specify a BE that is involved in another Live Upgrade operation. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. FILES
/etc/lutab list of BEs on the system /usr/share/lib/xml/dtd/lu_cli.dtd.<num> Live Upgrade DTD (see -X option) ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWluu | +-----------------------------+-----------------------------+ SEE ALSO
lu(1M), luactivate(1M), lucancel(1M), lucompare(1M), lucreate(1M), lucurr(1M), ludelete(1M), ludesc(1M), lumake(1M), lumount(1M), lure- name(1M), lustatus(1M), luupgrade(1M), lutab(4), attributes(5), live_upgrade(5) SunOS 5.10 24 Jan 2002 lufslist(1M)
All times are GMT -4. The time now is 09:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy