I have a simple .sh file which controls the empty space of the server. It simply shows red line if the usage is more than 90 percent and yellow line over 50 percent. I have more than 300 remote servers and I want to run my .sh file over ssh connection but I am having problems with it. I can not execute my for loop commands after making ssh connection in my .sh file. Here is the code below;
#!/bin/bash
TXT_BLD=$(tput bold)
TXT_RED=$(tput setaf 1)
TXT_YLW=$(tput setaf 3)
TXT_WARN="${TXT_BLD}${TXT_YLW}"
TXT_ERR="${TXT_BLD}${TXT_RED}"
TXT_RST=$(tput sgr0)
IFS= mapfile -t disk < <(df -h | tail -n +2)
for i in {01..21}; do
for j in {01..15}; do
ssh bc$i-$j
hostname="$(hostname)"
echo "#######${hostname}#######"
IFS= mapfile -t disk < <(df -h | tail -n +2)
for line in "${disk[@]}"; do
USAGE=$(echo $line | awk '{print $5/1}')
if [[ "$USAGE" -gt '90' ]]; then
echo "${TXT_ERR}$line${TXT_RST}"
elif [[ "$USAGE" -gt '50' ]]; then
echo "${TXT_WARN}$line${TXT_RST}"
else
echo "$line"
fi
done
done
done
I would be glad if you show me where my lackness is
thx