Update dsmon.sh

This commit is contained in:
2023-01-02 09:21:39 -06:00
parent 5f495e08eb
commit 1583165eba

View File

@@ -84,6 +84,8 @@ CHECK(){
declare -A host_ip declare -A host_ip
declare -A host_name declare -A host_name
declare -A host_limits declare -A host_limits
declare -A hostnames
declare -a hostnames_sort
while read hostid hostname hostip hostlimits; do while read hostid hostname hostip hostlimits; do
if [ "$hostid" != "id" ]; then if [ "$hostid" != "id" ]; then
@@ -92,13 +94,14 @@ CHECK(){
host_ip[${hostid}]=$hostip host_ip[${hostid}]=$hostip
host_name[${hostid}]=$hostname host_name[${hostid}]=$hostname
host_limits[${hostid}]=$hostlimits host_limits[${hostid}]=$hostlimits
hostnames[$hostname]=$hostid; hostnames_sort+=("$hostname")
fi fi
done <<< $(MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 3306 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts") done <<< $(MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 3306 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts")
IFS=$'\n' sorted=($(sort <<<"${host_name[*]}")) IFS=$'\n' sorted=($(sort <<<"${hostnames_sort[*]}"))
unset IFS unset IFS
for x in "${!host_name[@]}"; do printf "[%s]=%s\n" "$x" "${host_name[$x]}" ; done for x in "${!hostnames[@]}"; do printf "[%s]=%s\n" "$x" "${hostnames[$x]}" ; done
echo echo
for x in "${!sorted[@]}"; do printf "[%s]=%s\n" "$x" "${sorted[$x]}" ; done for x in "${!sorted[@]}"; do printf "[%s]=%s\n" "$x" "${sorted[$x]}" ; done