#!/bin/bash source /etc/profile cur_time=$(date "+%Y-%m-%d-%H-%M-%S") df_dirs=(${XYZ_DF_DIRS//:/ }) du_dirs=(${XYZ_DU_DIRS//:/ }) declare -A reports reports=(['cur_time']=$cur_time) function df_check() { # shellcheck disable=SC2068 for dir in ${df_dirs[@]} do ret=$(df -h | grep $dir | awk 'BEGIN{OFS=","}{print $2,$4}') key=${dir} reports[$key]=$ret done } function du_check() { # shellcheck disable=SC2068 for dir in ${du_dirs[@]} do if [ -d "$dir" ]; then cd $dir ret=$(du -h -d 0) key=${dir} reports[$key]=$ret fi done } df_check du_check str_report='' for key in $(echo ${!reports[*]}) do if [ ! -n "$str_report" ]; then str_report="$key:${reports[$key]}" else str_report="$str_report#$key:${reports[$key]}" fi done redis_host=$XYZ_REDIS_HOST netip=$XYZ_NETIP echo "HSET nc_disk_monitor $netip '$str_report'" | redis-cli -h $redis_host -p 6379