我刚刚编写了以下bash脚本来检查Linux机器列表上的ping访问:
for M in $list
do
ping -q -c 1 "$M" >/dev/null
if [[ $? -eq 0 ]]
then
echo "($C) $MACHINE CONNECTION OK"
else
echo "($C) $MACHINE CONNECTION FAIL"
fi
let C=$C+1
done
打印:
(1) linux643 CONNECTION OK
(2) linux72 CONNECTION OK
(3) linux862 CONNECTION OK
(4) linux12 CONNECTION OK
(5) linux88 CONNECTION OK
(6) Unix_machinetru64 CONNECTION OK
如何printf
在bash脚本中使用(或任何其他命令)以打印以下格式?
(1) linux643 ............ CONNECTION OK
(2) linux72 ............. CONNECTION OK
(3) linux862 ............ CONNECTION OK
(4) linux12 ............. CONNECTION OK
(5) linux88 ............. CONNECTION FAIL
(6) Unix_machinetru64 ... CONNECTION OK
$TOTAL (length) - $MASHINE (length)
以获得点数。然后printf '.%.s' {1..$DOTS}
在每个循环迭代中使用。我认为这样的事情会起作用。