Write file via cat
#!/bin/bash
client_id='1';
####
eth_ip=$(ip addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f 1);
eth_mac=$(ip addr show eth0 | awk '/ether / {print $2}');
wlan_ip=$(ip addr show wlan0 | awk '/inet / {print $2}' | cut -d/ -f 1);
wlan_mac=$(ip addr show wlan0 | awk '/ether / {print $2}');
gw_ip=$(ip r | awk '/default / {print $3}' | sed '2,1d');
####
os_release=$(lsb_release -sd)
hdd_free=$(df -h | grep /dev/root | awk '{print $4}' | cut -c1,2)
ram_free=$(free -mh | awk 'NR==2{print $7}' | cut -c1,2,3)
host_temp=$(vcgencmd measure_temp | cut -d\= -f2 | cut -d\' -f1)
mount_folder="/dev/mmc"
######### Write JSON File #########
cat <<EOF > client_data.json
{
"id" : "$client_id",
"name": "$HOSTNAME",
"os": "$os_release",
"ressources": [
{"hdd_free": "$hdd_free", "type": "GB"},
{"ram_free": "$ram_free", "type": "MB"}
],
"network": [
{"eth_ip": "$eth_ip", "eth_mac": "$eth_mac"},
{"wlan_ip": "$wlan_ip", "wlan_mac": "$wlan_mac"},
{"gw_ip": "$gw_ip"}
],
"temperature": [
{"temperature": "$host_temp"}
]
}
EOFLast updated