How can we properly handle basham, for example, the same output fping to get the output at the output - the node is available or unavailable - with a minimum delay from the moment the script is run. Errors in the form of a failed first ping are not taken into account - the grid is local.

  • one
    install fping. It is just for this purpose. - KoVadim
  • I would like to be able to organize it without any third-party utilities, only with bash tools) - Dofri
  • one
    and the usual ping does not suit you too? - KoVadim
  • 2
    1) Only using bash means this is impossible; bash itself cannot work with the network. 2) What do you mean by "node availability"? - user194374
  • one
    Ping using a single package, for example: ping -c1 <host> > /dev/null && echo "host is UP" || echo "host is DOWN" ping -c1 <host> > /dev/null && echo "host is UP" || echo "host is DOWN" - approximatenumber

1 answer 1

You can use the ping utility by sending one packet ( -c1 ) to check the availability of a node. Depending on the return value of the utility output, it is possible to signal the availability or unavailability of a node. For example:

 host="192.168.222.222" ping -c1 "$host" > /dev/null && echo ""$host" is UP" || echo ""$host" is DOWN" 
  • “The errors in the form of a failed first ping are not taken into account - the grid is local.” - One package will not be enough for such a requirement. - edem
  • In this case, @edem will have to add one packet at a time until clarity is reached :) in fact, seriously, if there is a temporary lack of ICMP responses, it would be good to think about the reasons for this phenomenon - approximatenumber
  • @edem, you can send more packets. as far as I remember, the logic for generating the return code for the ping program is such that zero will return even if at least one answer is received. - aleksandr barakin