Chcę stworzyć skrypt w Bash'u, który zbierałby informację o serwerze, a następnie wysyłał w formacie JSON do API z metodą post... Niestety nie potrafię sobie z tym poradzić, tutaj mam już fragment kodu i nie wiem co dalej...
#/bin/bash
# CRM HEARTBEAT CLIENT
# VERSION: 0.1.2
API_PING_URL='adres url';
HOSTNAME=$1;
if [ -z "$HOSTNAME" ]; then
echo "Error: Please give hostname as script argument, e.g. ./client.sh crm.domain.com";
exit;
fi
CPU_LOAD=$(uptime | awk -F'load average:' '{ print $2 }');
MEMORY_RAM_TOTAL=$(free | awk '/^Mem:/{print $2}');
MEMORY_RAM_USED=$(free | awk '/^Mem:/{print $3}');
MEMORY_SWAP_TOTAL=$(free | awk '/^Swap:/{print $2}');
MEMORY_SWAP_USED=$(free | awk '/^Swap:/{print $3}');
HDD_TOTAL=$(df | grep '/$' | awk '{print $2}');
HDD_USED=$(df | grep '/$' | awk '{print $3}');
GIT_MODIFIED_COUNT=0;
A=$(curl -d "hostname=${HOSTNAME}&cpu_load=${CPU_LOAD}&memory_ram_total=${MEMORY_RAM_TOTAL}&memory_ram_used=${MEMORY_RAM_USED}&memory_swap_total=${MEMORY_SWAP_TOTAL}&memory_swap_used=${MEMORY_SWAP_USED}&hdd_total=${HDD_TOTAL}&hdd_used=${HDD_USED}&git_modified_count=0" "$API_PING_URL");
echo $A;
i format w jakim byłoby to wysyłane wyglądałby tak
{
"account_uuid": "AGC43367-ED6B-12B8-B634-A7C0135C24E1",
"server_uuid": "A2234567-0FPP-33B9-7999-12347BB61234",
"hostname": "Lukasz.home",
"ip": [
"190.134.2.11",
"10.70.70.10"
],
"cpu_load": "2.88, 2.34, 2.29",
"memory_ram_total": 4046444,
"memory_ram_used": 372016,
"memory_swap_total": 524284,
"memory_swap_used": 0,
"hdd": [
{
"partition": "/dev/disk0s2",
"label": "/",
"total": 497926976,
"used": 448504360
},
{
"partition": "/dev/disk1s3",
"label": "/Volumes/Firma",
"total": 585937504,
"used": 334393432
},
{
"partition": "/dev/disk1s4",
"label": "/Volumes/Www",
"total": 585141552,
"used": 119892288
}
]
}