some_scripts/wholive

45 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Пингуем машины, проверяем, кто доступен, а кто нет.
# Адреса машин находятся в hosts
#
# TO-DO
# [X] - спрятать все в цикл
# [X] - анализатор хостс (возможно не нужен, можно выписывать именна в массив)
# [X] - табличная верстка вывода
# [ ] - добавить цвет в вывод
RED='\033[31m'
GRN='\033[32m'
DEF='\033[0m'
fail="dead"
suc="alive"
stands=('lgbt' 'stan' 'sheldon' 'zombie' 'notebook' 'dock')
table_print() {
printf '%10s %-6s%-9s\n' $1 $2 $3
}
test_ping() {
for stand in ${stands[@]}; do
if ping -W 1 -c 1 $stand &> /dev/null; then
table_print $stand $suc "$(date +%X)"
else
table_print $stand $fail "$(date +%X)"
fi
done
}
test_arp() {
for stand in ${stands[@]}; do
if /usr/sbin/arp $stand | grep -cq incomplete; then
table_print $stand $fail "$(date +%X)"
else
table_print $stand $suc "$(date +%X)"
fi
done
}
test_arp