Reputation: 2071
I've spent way to long trying to figure this out, so I hope someone can shed some light on this.
#!/bin/bash
HOSTNAME="`hostname`"
JSONFILE="${HOSTNAME}.json"
#####################
# FUNCTIONS #
#####################
function getfilesystems() {
count=0;
FILESYSTEMS=()
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for fs in `df -P | awk 'NR!=1'`; do
FILESYSTEMS+=("fs$count=${fs}")
(( count++ ))
done
echo "${FILESYSTEMS[@]}"
IFS=$SAVEIFS
}
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
jo -p serverdata="$(jo hostname=${HOSTNAME} reportdata="$(date)" storage="$(jo -p "$(getfilesystems)")")"
IFS=$SAVEIFS
I'm trying to focus on this part FILESYSTEMS+=("fs$count=${fs}")
Right now, the output is this:
'fs0=/dev/mapper/vg_rpidalappnfs-LogVol00 10190136 5486908 4178940 57% /' 'fs1=tmpfs 1962684 4 1962680 1% /dev/shm' 'fs2=/dev/sda1 194241 104145 79856 57% /boot'
It's almost what I want. What I need is this (see the quotes difference?):
fs0="/dev/mapper/vg_rpidalappnfs-LogVol00 10190136 5486908 4178940 57% /" fs1="tmpfs 1962684 4 1962680 1% /dev/shm" fs2="/dev/sda1 194241 104145 79856 57% /boot"
I've literally been trying to get this to work for about an hour and I just can't seem to get past this one part.
The help is appreciated.
Upvotes: 0
Views: 61
Reputation: 241968
Escape the doublequote by a backslash:
FILESYSTEMS+=("fs$count=\"${fs}")
But I fear you won't need the doublequotes in the output in the end, but I'm not familiar with jo
.
Upvotes: 1