From 25d739c67d5c5cbef7ef5178774dedd77de548d3 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Tue, 12 Mar 2024 10:03:37 -0500 Subject: [PATCH] Update dsmon.sh --- dsmon.sh | 74 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/dsmon.sh b/dsmon.sh index f5a1904..fe4ffce 100755 --- a/dsmon.sh +++ b/dsmon.sh @@ -337,48 +337,48 @@ RUNCMD(){ echo -e "${idsST[Bold]}'${idsCL[LightCyan]}$(echo "${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} ${19} ${20}" | awk '{$1=$1};1')${idsCL[White]}'${idsCL[Default]}${idsST[Reset]}\n" ncount=0 + # while read hostid hostname hostip hostlimits; do + # if [ "${hostname}" != "host" ]; then + # ssh -tq -o ConnectTimeout=3 -o ConnectionAttempts=1 root@${hostip} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} ${19} ${20} ${21} ${22} + # fi + # done <<< $(MYSQL_PWD="sysmoninsert" mysql -h ${mysqlip} -P 3307 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts WHERE disabled=0 ORDER BY host ASC") + while read hostid hostname hostip hostlimits; do if [ "${hostname}" != "host" ]; then - ssh -tq -o ConnectTimeout=3 -o ConnectionAttempts=1 root@${hostip} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} ${19} ${20} ${21} ${22} + RUNCMD_SUB $(echo ${hostip} | cut -d ";" -f1) ${hostname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} ${19} ${20} ###& + ((ncount++)) fi done <<< $(MYSQL_PWD="sysmoninsert" mysql -h ${mysqlip} -P 3307 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts WHERE disabled=0 ORDER BY host ASC") - - # while read hostid hostname hostip hostlimits; do - # if [ "${hostname}" != "host" ]; then - # RUNCMD_SUB $(echo ${hostip} | cut -d ";" -f1) ${hostname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} ${19} ${20} ###& - # ((ncount++)) - # fi - # done <<< $(MYSQL_PWD="sysmoninsert" mysql -h ${mysqlip} -P 3307 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts WHERE disabled=0 ORDER BY host ASC") - # - # nc_count=0; lcount=0; completed=false - # until [ "${completed}" == "true" ]; do - # for nodecmd in /tmp/.dsmon.runcmd.*.done; do - # # HOST=$(grep -oP '(?<=runcmd.).*?(?=.done)' <<< "${nodecmd}") - # # if [ "${HOST}" != "*" ]; then - # # if [[ "${nodecmd}" != *"*"* ]]; then - # # nodecmd_output=$(cat ${nodecmd}) - # # [ "${nodecmd_output}" != "" ] && echo -e "${nodecmd_output}\n" - # # fi - # # rm -f ${nodecmd} - # - # if [[ "${nodecmd}" != *"*"* ]]; then - # nodecmd_output=$(cat ${nodecmd}) - # [ "${nodecmd_output}" != "" ] && echo -e "${nodecmd_output}\n" - # rm -f ${nodecmd} - # ((nc_count++)) - # fi - # done - # if [ ${nc_count} -eq ${ncount} ]; then - # echo -e "${idsCL[LightGreen]}Complete, the command was ran on all nodes\n" - # completed=true - # break - # fi - # [ ${lcount} -ne ${nc_count} ] && echo -e "${idsCL[Yellow]}${nc_count} of ${ncount} completed ...\n" - # lcount=${nc_count} - # - # sleep 2s - # done + + nc_count=0; lcount=0; completed=false + until [ "${completed}" == "true" ]; do + for nodecmd in /tmp/.dsmon.runcmd.*.done; do + # HOST=$(grep -oP '(?<=runcmd.).*?(?=.done)' <<< "${nodecmd}") + # if [ "${HOST}" != "*" ]; then + # if [[ "${nodecmd}" != *"*"* ]]; then + # nodecmd_output=$(cat ${nodecmd}) + # [ "${nodecmd_output}" != "" ] && echo -e "${nodecmd_output}\n" + # fi + # rm -f ${nodecmd} + + if [[ "${nodecmd}" != *"*"* ]]; then + nodecmd_output=$(cat ${nodecmd}) + [ "${nodecmd_output}" != "" ] && echo -e "${nodecmd_output}\n" + rm -f ${nodecmd} + ((nc_count++)) + fi + done + if [ ${nc_count} -eq ${ncount} ]; then + echo -e "${idsCL[LightGreen]}Complete, the command was ran on all nodes\n" + completed=true + break + fi + [ ${lcount} -ne ${nc_count} ] && echo -e "${idsCL[Yellow]}${nc_count} of ${ncount} completed ...\n" + lcount=${nc_count} + + sleep 2s + done echo end=`date +%s`