用于循环的Shell脚本输出无序的数字序列

时间:2015-12-24 00:06:44

标签: bash shell

我在下面编写了如下所示的shell脚本,输出如

redis-health-checker: Ping failed 1
redis-health-checker: Ping failed 3
redis-health-checker: Ping failed 2

但它应该输出像

redis-health-checker: Ping failed 1
redis-health-checker: Ping failed 2
redis-health-checker: Ping failed 3

(这个脚本是一个简单的检查脚本,用于查看redis-server是否存活,如果它停止工作则告诉Keepalived。)

#!/bin/bash

for TRIES in $(seq 1 3)
do
  RESULT=$($REDIS_CLI ping)
  if [ "${/etc/redis-cli}" = "PONG" ]; then
    exit 0
  fi
  echo "Ping failed ${TRIES}" | logger -t redis-health-checker
  sleep 1
done

exit 1 # Makes Keepalived FALL

0 个答案:

没有答案