bash shell脚本以使用IPS监视文件

发布于 2025-02-06 16:53:19 字数 6577 浏览 1 评论 0 原文

我希望构建一个脚本,在上下时,我可以在其中用ping命令监视IP的文件。

我在Stackoverflow上找到了两种出色的方法,我正在尝试将它们结合起来,但是无论我做什么都行不通。我正在阅读Man Shell也可以学习以后的学习,但我认为我缺少一些东西,无法使它起作用。

脚本1:

我似乎找不到我在stackoverflow上找到的脚本,但在此资源下找到了相同的脚本:(bash and ping)部分: https://jmanteau.fr.fr.fr.fr.fr.fr.fr.fr /posts/ping的facets/#check-if-if-host-hosts-are-alive

这个惊人的脚本可以在并行

#!/bin/bash

argc=$#
if [ $# -lt 1 ]
then
   echo "Usage: $0 <ip-list-file>"
   exit 1
fi

hosts=$1

function customping 
{
    DATE=$(date '+%d/%m/%Y %H:%M:%S')
    ping -c 1 -W 1 $1 >/dev/null 2>&1 && echo "$DATE Node $1 is UP" || echo -e "\033[1;31m $DATE Node $1 is DOWN \033[0m"
# ping -c 1 -W 1 $1 >/dev/null 2>&1 && echo "$DATE Node $1 is UP" || echo "$DATE Node $1 is DOWN"
# sleep 0.01s
}

T="$(date +%s%N)"

DEFAULT_NO_OF_PROC=8
noofproc=$DEFAULT_NO_OF_PROC

if [ -n "$2" ] #user-set no. of process instead of default
then
  noofproc=$2
  echo "Max processes: $noofproc"
fi

export -f customping && cat $hosts | xargs -n 1 -P $noofproc -I{} bash -c 'customping {}' \;

脚本2:

这个令人惊叹的脚本通过IP

function check_health {

set 192.168.10.1 192.168.10.2 192.168.10.3 192.168.10.4 192.168.10.5 192.168.10.6 192.168.10.7 192.168.10.8 192.168.10.9 192.168.10.10 192.168.10.11 192.168.10.12 192.168.10.13

trap exit 2

for ipnumber in "$@"; do
  DATE=$(date '+%d/%m/%Y %H:%M:%S')
  ping -c 1 -t 1 $ipnumber > /dev/null
  [ $? -eq 0 ] && echo -e "|\033[1;36m $DATE \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
done

while true; do
  i=1
  for ipnumber in "$@"; do
    statusname=up$i
    laststatus=${!statusname:-0}
    ping -c 1 -t 1 $ipnumber > /dev/null
    ok=$?
    eval $statusname=$ok
    if [ ${!statusname} -ne $laststatus ]; then
      # echo $DATE Status changed for $ipnumber
      DATE=$(date '+%d/%m/%Y %H:%M:%S')
      if [ $ok -eq 0 ]; then
        echo -e "|\033[1;36m $DATE \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
      else
        echo -e "|\033[1;36m $DATE \033[0m" "|\033[1;31m Node |"$ipnumber "| DOWN \033[0m" | column -t -s "|"
      fi
    fi
    i=$(($i + 1))
  done
 # sleep 1
done

}

stackoverflow.com/a/470831/19313640" > https://stackoverflow.com/a/a/4708831/19313640 将这2个脚本放在一起,并将其完全并行为第一个脚本,并通过阅读文件而不是第二个脚本中的“设置”,还可以使用第二个脚本的监视功能。

编辑:如果使此工作至少如何使第二个脚本像第一个脚本一样读取文件是复杂的?

我希望我很彻底,并提供了足够的信息,以了解我要做的事情。

谢谢。


更新:

您好,我设法使其在凌乱的代码中起作用。

#!/bin/bash

trap exit 2

argc=$#
if [ $# -lt 1 ]
then
   echo "Usage: $0 <ip-list-file>"
   exit 1
fi

hosts=$1


function check_live {

  trap exit 2

  DATE=$(date '+%d/%m/%Y %H:%M:%S')
    ping -c 1 -t 1 $1 > /dev/null
    [ $? -eq 0 ] && echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$1 "| UP \033[0m" | column -t -s "|"
    # sleep 1
}

function check_health {

  trap exit 2

#  DATE=$(date '+%d/%m/%Y %H:%M:%S')
#    ping -c 1 -t 1 $1 > /dev/null
#    [ $? -eq 0 ] && echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$1 "| UP \033[0m" | column -t -s "|"
#    sleep 3

  while true; do
  # while read line; do 
  # i="$i $line"
    i=1
    for ipnumber in "$@"; do
      statusname=up$i
      laststatus=${!statusname:-0}
      ping -c 1 -t 1 $ipnumber > /dev/null
      ok=$?
      eval $statusname=$ok
      if [ ${!statusname} -ne $laststatus ]; then
        # echo $DATE Status changed for $ipnumber
        DATE=$(date '+%d/%m/%Y %H:%M:%S')
        if [ $ok -eq 0 ]; then
          echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
        else
          echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;31m Node |"$ipnumber "| DOWN \033[0m" | column -t -s "|"
        fi
      fi
      i=$(($i + 1))
    done
   # sleep 1
  done
}

function duck_art {

textred=$(tput setaf 1)
textcyan=$(tput setaf 12)
textyellow=$(tput setaf 11)
textpurple=$(tput setaf 4)
textpink=$(tput setaf 5)
textwhite=$(tput setaf 7)
textgray=$(tput setaf 8)
textgreen=$(tput setaf 10)


echo -e ${textpink} ================================================================
cat <<EOM
${textyellow}
EOM
cat << "EOF"
                  __                         __
              ___( o)>       DuckLab       <(o )___
              \ <_. )        Monitor        ( ._> /
               `---'                         `---' 
EOF
echo -e ${textpink} ================================================================
echo -e ${textyellow} "                    Press <CTRL+C> to exit.                   "
echo -e ${textpink} ================================================================
echo -e "\033[1;36m  $internal_ip \033[0m" "     ${textpink}|     " "\033[1;36m $my_name \033[0m" "     ${textpink}|     " "\033[1;36m $external_ip \033[0m"
echo -e ${textpink} ================================================================
}


external_ip=$(curl -s ifconfig.me)

internal_ip=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')

my_name=$(hostname)



function multi_process_live {
T="$(date +%s%N)"

DEFAULT_NO_OF_PROC=8
noofproc=$DEFAULT_NO_OF_PROC

if [ -n "$2" ] #user-set no. of process instead of default
  then
    noofproc=$2
    echo "Max processes: $noofproc"
  fi

export -f check_live && cat $hosts | xargs -n 1 -P $noofproc -I{} bash -c 'check_live  {}' \; 2>/dev/null 
}



function multi_process_health {
T="$(date +%s%N)"

DEFAULT_NO_OF_PROC=8
noofproc=$DEFAULT_NO_OF_PROC

if [ -n "$2" ] #user-set no. of process instead of default
  then
    noofproc=$2
    echo "Max processes: $noofproc"
  fi

export -f check_health && cat $hosts | xargs -n 1 -P $noofproc -I{} bash -c 'check_health  {}' \; 2>/dev/null 
}



# ================================ End of fucntions ================================

# ================================ Start of Script =================================

clear
duck_art
multi_process_live
multi_process_health

# ================================ End of Script ===================================

检查实时主机工作的第一个功能。 循环循环的第二个功能显示初始输出,但未正确循环通过文件的每一行,以监视哪些主机向上或向下并打印输出。它仅适用于第二行,我认为它不能正确读取文件的每行。

使这项工作和学习的任何想法,改进和建议都受到高度重视。

谢谢。

I am looking to build a script where I can monitor a file of IPs with ping command when Up or Down.

I have found two excellent methods on stackoverflow and i am trying to combine them but whatever I do it does not work. I am reading man shell to learn for future as well but I think I am missing something and cannot make it work.

Script 1:

I cannot seem to find the script i found on stackoverflow but found the same under this resource: (Bash and Ping) section in:
https://jmanteau.fr/posts/the-facets-of-ping/#check-if-many-hosts-are-alive

This amazing script can ping very fast multiple hosts in parallel

#!/bin/bash

argc=$#
if [ $# -lt 1 ]
then
   echo "Usage: $0 <ip-list-file>"
   exit 1
fi

hosts=$1

function customping 
{
    DATE=$(date '+%d/%m/%Y %H:%M:%S')
    ping -c 1 -W 1 $1 >/dev/null 2>&1 && echo "$DATE Node $1 is UP" || echo -e "\033[1;31m $DATE Node $1 is DOWN \033[0m"
# ping -c 1 -W 1 $1 >/dev/null 2>&1 && echo "$DATE Node $1 is UP" || echo "$DATE Node $1 is DOWN"
# sleep 0.01s
}

T="$(date +%s%N)"

DEFAULT_NO_OF_PROC=8
noofproc=$DEFAULT_NO_OF_PROC

if [ -n "$2" ] #user-set no. of process instead of default
then
  noofproc=$2
  echo "Max processes: $noofproc"
fi

export -f customping && cat $hosts | xargs -n 1 -P $noofproc -I{} bash -c 'customping {}' \;

Script 2:

https://stackoverflow.com/a/4708831/19313640

This amazing script loops through the IPs and shows if down or up (monitoring)

function check_health {

set 192.168.10.1 192.168.10.2 192.168.10.3 192.168.10.4 192.168.10.5 192.168.10.6 192.168.10.7 192.168.10.8 192.168.10.9 192.168.10.10 192.168.10.11 192.168.10.12 192.168.10.13

trap exit 2

for ipnumber in "$@"; do
  DATE=$(date '+%d/%m/%Y %H:%M:%S')
  ping -c 1 -t 1 $ipnumber > /dev/null
  [ $? -eq 0 ] && echo -e "|\033[1;36m $DATE \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
done

while true; do
  i=1
  for ipnumber in "$@"; do
    statusname=up$i
    laststatus=${!statusname:-0}
    ping -c 1 -t 1 $ipnumber > /dev/null
    ok=$?
    eval $statusname=$ok
    if [ ${!statusname} -ne $laststatus ]; then
      # echo $DATE Status changed for $ipnumber
      DATE=$(date '+%d/%m/%Y %H:%M:%S')
      if [ $ok -eq 0 ]; then
        echo -e "|\033[1;36m $DATE \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
      else
        echo -e "|\033[1;36m $DATE \033[0m" "|\033[1;31m Node |"$ipnumber "| DOWN \033[0m" | column -t -s "|"
      fi
    fi
    i=$(($i + 1))
  done
 # sleep 1
done

}

So my question is how to put these 2 scripts together and make it completely in parallel as first script and by reading a file instead of "set" in second script, but also with the monitor capabilities of the second script.

Edit: If it is complicated to make this work at least how can i make the second script read a file as argument as the first script does?

I hope I was thorough and gave enough info of what i am trying to do.

Thank you.


Update:

Hello again, I have manage to made it work in a messy code.

#!/bin/bash

trap exit 2

argc=$#
if [ $# -lt 1 ]
then
   echo "Usage: $0 <ip-list-file>"
   exit 1
fi

hosts=$1


function check_live {

  trap exit 2

  DATE=$(date '+%d/%m/%Y %H:%M:%S')
    ping -c 1 -t 1 $1 > /dev/null
    [ $? -eq 0 ] && echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$1 "| UP \033[0m" | column -t -s "|"
    # sleep 1
}

function check_health {

  trap exit 2

#  DATE=$(date '+%d/%m/%Y %H:%M:%S')
#    ping -c 1 -t 1 $1 > /dev/null
#    [ $? -eq 0 ] && echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$1 "| UP \033[0m" | column -t -s "|"
#    sleep 3

  while true; do
  # while read line; do 
  # i="$i $line"
    i=1
    for ipnumber in "$@"; do
      statusname=up$i
      laststatus=${!statusname:-0}
      ping -c 1 -t 1 $ipnumber > /dev/null
      ok=$?
      eval $statusname=$ok
      if [ ${!statusname} -ne $laststatus ]; then
        # echo $DATE Status changed for $ipnumber
        DATE=$(date '+%d/%m/%Y %H:%M:%S')
        if [ $ok -eq 0 ]; then
          echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
        else
          echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;31m Node |"$ipnumber "| DOWN \033[0m" | column -t -s "|"
        fi
      fi
      i=$(($i + 1))
    done
   # sleep 1
  done
}

function duck_art {

textred=$(tput setaf 1)
textcyan=$(tput setaf 12)
textyellow=$(tput setaf 11)
textpurple=$(tput setaf 4)
textpink=$(tput setaf 5)
textwhite=$(tput setaf 7)
textgray=$(tput setaf 8)
textgreen=$(tput setaf 10)


echo -e ${textpink} ================================================================
cat <<EOM
${textyellow}
EOM
cat << "EOF"
                  __                         __
              ___( o)>       DuckLab       <(o )___
              \ <_. )        Monitor        ( ._> /
               `---'                         `---' 
EOF
echo -e ${textpink} ================================================================
echo -e ${textyellow} "                    Press <CTRL+C> to exit.                   "
echo -e ${textpink} ================================================================
echo -e "\033[1;36m  $internal_ip \033[0m" "     ${textpink}|     " "\033[1;36m $my_name \033[0m" "     ${textpink}|     " "\033[1;36m $external_ip \033[0m"
echo -e ${textpink} ================================================================
}


external_ip=$(curl -s ifconfig.me)

internal_ip=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')

my_name=$(hostname)



function multi_process_live {
T="$(date +%s%N)"

DEFAULT_NO_OF_PROC=8
noofproc=$DEFAULT_NO_OF_PROC

if [ -n "$2" ] #user-set no. of process instead of default
  then
    noofproc=$2
    echo "Max processes: $noofproc"
  fi

export -f check_live && cat $hosts | xargs -n 1 -P $noofproc -I{} bash -c 'check_live  {}' \; 2>/dev/null 
}



function multi_process_health {
T="$(date +%s%N)"

DEFAULT_NO_OF_PROC=8
noofproc=$DEFAULT_NO_OF_PROC

if [ -n "$2" ] #user-set no. of process instead of default
  then
    noofproc=$2
    echo "Max processes: $noofproc"
  fi

export -f check_health && cat $hosts | xargs -n 1 -P $noofproc -I{} bash -c 'check_health  {}' \; 2>/dev/null 
}



# ================================ End of fucntions ================================

# ================================ Start of Script =================================

clear
duck_art
multi_process_live
multi_process_health

# ================================ End of Script ===================================

First function which checks for live hosts works.
Second function which loops shows initial output but doesnt loop correctly through each line of the file to monitor which hosts are UP or Down and print output. It does that only for the second line, which I assume it does not read each line of the file correctly.

Any ideas, improvements and suggestions to make this work and learn are highly valued.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁我热情 2025-02-13 16:53:19

请注意,原始脚本的魔法是使用 XARGS -P $ NOOFPROC 并行运行检查。

在不知道您的主机列表的情况下,很难猜测您在第一行中看到什么问题。我最好的猜测是,对于您的第一个条目, ping 退出代码不是零,它没有退出任何东西。

我看到了您最新的 check_health 功能的一些问题。

  • 虽然true 循环,正如您
  • 在“ $*” 中指出的 ,这是没有意义的,因为您还是一次将其调用一个条目。
  • 从中流动的问题是,每个调用 check_health 将以 i = 1 开始这些调用中的每一个都将设置相同的状态名称 up1 )最终将被使用。

这是我建议的(我希望您不要介意我从脚本中删除了非必需品位):

#!/bin/bash

trap exit 2

argc=$#
if [ $# -lt 1 ]; then
    echo "Usage: $0 <ip-list-file>"
    exit 1
fi

hosts=$1

function check_live {
    trap exit 2

    DATE=$(date '+%d/%m/%Y %H:%M:%S')
    ping -c 1 -t 1 $1 > /dev/null
    [ $? -eq 0 ] && echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$1 "| UP \033[0m" | column -t -s "|"
}

function check_health {
    trap exit 2

    i=$1
    ipnumber=$2
    statusname=up$1
    laststatus=${!statusname:-0}
    ping -c 1 -t 1 $ipnumber > /dev/null
    ok=$?
    eval $statusname=$ok
    if [ ${!statusname} -ne $laststatus ]; then
        DATE=$(date '+%d/%m/%Y %H:%M:%S')
        if [ $ok -eq 0 ]; then
            echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
        else
            echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;31m Node |"$ipnumber "| DOWN \033[0m" | column -t -s "|"
        fi
    fi
}

function multi_process_live {
    T="$(date +%s%N)"

    DEFAULT_NO_OF_PROC=8
    noofproc=$DEFAULT_NO_OF_PROC

    if [ -n "$2" ]; then
        #user-set no. of process instead of default
        noofproc=$2
        echo "Max processes: $noofproc"
    fi

    export -f check_live
    cat $hosts | xargs -n 1 -P $noofproc -I{} bash -c 'check_live  {}' \; 2>/dev/null
}

function multi_process_health {
    T="$(date +%s%N)"

    DEFAULT_NO_OF_PROC=8
    noofproc=$DEFAULT_NO_OF_PROC

    if [ -n "$2" ]; then
        #user-set no. of process instead of default
        noofproc=$2
        echo "Max processes: $noofproc"
    fi

    export -f check_health
    awk '{print FNR " " $1}' < $hosts | xargs -n2 -P $noofproc -I{} bash -c 'check_health  {}' \; 2>/dev/null
}

multi_process_live
while true; do
    multi_process_health
    sleep 1
done

运行初始实时检查,然后运行Multi_process_health功能。

关键是两件事。首先,使用 awk'{print fnr“” $ 1}',它符合主机列表:

127.0.0.1
10.0.0.1
192.168.0.1

进入此:

1 127.0.0.1
2 10.0.0.1
3 192.168.0.1

第二, xargs -n2 的使用使其每一个都如此呼叫 check_health 将序列编号作为第一个参数,而实际主机作为第二个参数。

A note that the magic of the original script was in using xargs -P $noofproc, to run the check in parallel.

Without knowing what your list of hosts looks like, it is difficult to guess what problem you're seeing with the first line. My best guess is that for your first entry the ping exit code was non-zero and it just didn't exit anything.

I see a few issues with your most recent check_health function.

  • The while true loop, as you noted
  • The for ipnumber in "$*" which makes no sense since you're calling it with one entry at a time anyway.
  • The problem that flows from that is that each call to check_health will start with i=1, so even if the while true wasn't there each of these calls would be setting the same statusname (up1) will end up getting used.

Here is what I would suggest (I hope you don't mind that I removed the non-essential bits from your script):

#!/bin/bash

trap exit 2

argc=$#
if [ $# -lt 1 ]; then
    echo "Usage: $0 <ip-list-file>"
    exit 1
fi

hosts=$1

function check_live {
    trap exit 2

    DATE=$(date '+%d/%m/%Y %H:%M:%S')
    ping -c 1 -t 1 $1 > /dev/null
    [ $? -eq 0 ] && echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$1 "| UP \033[0m" | column -t -s "|"
}

function check_health {
    trap exit 2

    i=$1
    ipnumber=$2
    statusname=up$1
    laststatus=${!statusname:-0}
    ping -c 1 -t 1 $ipnumber > /dev/null
    ok=$?
    eval $statusname=$ok
    if [ ${!statusname} -ne $laststatus ]; then
        DATE=$(date '+%d/%m/%Y %H:%M:%S')
        if [ $ok -eq 0 ]; then
            echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
        else
            echo -e "|\033[1;36m  $DATE \033[0m" "|\033[1;31m Node |"$ipnumber "| DOWN \033[0m" | column -t -s "|"
        fi
    fi
}

function multi_process_live {
    T="$(date +%s%N)"

    DEFAULT_NO_OF_PROC=8
    noofproc=$DEFAULT_NO_OF_PROC

    if [ -n "$2" ]; then
        #user-set no. of process instead of default
        noofproc=$2
        echo "Max processes: $noofproc"
    fi

    export -f check_live
    cat $hosts | xargs -n 1 -P $noofproc -I{} bash -c 'check_live  {}' \; 2>/dev/null
}

function multi_process_health {
    T="$(date +%s%N)"

    DEFAULT_NO_OF_PROC=8
    noofproc=$DEFAULT_NO_OF_PROC

    if [ -n "$2" ]; then
        #user-set no. of process instead of default
        noofproc=$2
        echo "Max processes: $noofproc"
    fi

    export -f check_health
    awk '{print FNR " " $1}' < $hosts | xargs -n2 -P $noofproc -I{} bash -c 'check_health  {}' \; 2>/dev/null
}

multi_process_live
while true; do
    multi_process_health
    sleep 1
done

That runs the initial live check and then runs the multi_process_health function.

The key is two things. First the use of awk '{print FNR " " $1}' which turns a list of hosts:

127.0.0.1
10.0.0.1
192.168.0.1

Into this:

1 127.0.0.1
2 10.0.0.1
3 192.168.0.1

Second the use of xargs -n2 which makes it so each call to check_health is given the sequence number as the first parameter and the actual host as the second parameter.

假情假意假温柔 2025-02-13 16:53:19

如果主机数量适合您的屏幕,请尝试以下操作:

healthcheck() {
    ipnumber=$1
    last="-1"
    while true; do
        date=$(date -Is)
        ping -c 1 -t 20 $ipnumber > /dev/null 2>/dev/null
        latest=$?
        if [ $last -ne $latest ] ; then
            # status changed                                                                                                                        
            if [ $latest -eq 0 ] ; then
                echo -e "|\033[1;36m  $date \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
            else
                echo -e "|\033[1;36m  $date \033[0m" "|\033[1;31m Node |"$ipnumber "| DOWN \033[0m" | column -t -s "|"
            fi
        fi
        last=$latest
        sleep 1
    done
}
export -f healthcheck

cat hostlist | parallel-20220622 -j0 --ll healthcheck

如果您没有并行-20220622,则可能足够:

cat hostlist | parallel -j0 --lb healthcheck

If the number of hosts fit on your screen, then try this:

healthcheck() {
    ipnumber=$1
    last="-1"
    while true; do
        date=$(date -Is)
        ping -c 1 -t 20 $ipnumber > /dev/null 2>/dev/null
        latest=$?
        if [ $last -ne $latest ] ; then
            # status changed                                                                                                                        
            if [ $latest -eq 0 ] ; then
                echo -e "|\033[1;36m  $date \033[0m" "|\033[1;32m Node |"$ipnumber "| UP \033[0m" | column -t -s "|"
            else
                echo -e "|\033[1;36m  $date \033[0m" "|\033[1;31m Node |"$ipnumber "| DOWN \033[0m" | column -t -s "|"
            fi
        fi
        last=$latest
        sleep 1
    done
}
export -f healthcheck

cat hostlist | parallel-20220622 -j0 --ll healthcheck

If you do not have parallel-20220622 this might be enough:

cat hostlist | parallel -j0 --lb healthcheck
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文