0
所以我有一些問題聲明一個數組的變量。 我想爲每個數組迭代確定兩個變量(STATUS和CONSUMERS)。在數組中聲明變量
#!/bin/bash
QUEUE=(outbound.queue, inbound.queue, outbound.queue.optin)
DATE="$(date)"
MESSAGE="${QUEUE[$i]} is active with no Consumers at $DATE"
DESC="Please check rabbitmq for info on $HOSTNAME"
ALIAS="${QUEUE[$i]} $HOSTNAME"
for i in "${QUEUE[@]}"; do
STATUS[$i]=$(sudo /usr/sbin/rabbitmqctl list_queues name status | grep "^${QUEUE[@]}\s" | sed "s/${QUEUE[@]}\s//")
CONSUMERS[$i]=$(sudo /usr/sbin/rabbitmqctl list_queues name consumers | grep "^${QUEUE[@]}\s" | sed "s/${QUEUE[@]}\s//")
if [ "${STATUS[$i]}" = "running" ];
then
echo "$QUEUE[$i] is running";
if [ "${CONSUMERS[$i]}" = "0" ];
then
lamp createAlert;
fi
else
echo "$QUEUE is not running";
fi
done
什麼最終以眼下的情況是要麼(取決於@或*在$ QUEUE []爲)嘗試使用所有變量的一次,或用 line 13: outbound.queue: syntax error: invalid arithmetic operator (error token is ".queue")
任何幫助,將不勝感激:)
echo「$ QUEUE [$ i] running」is wrong because you must use braces:$ {QUEUE [$ i]} – Jdamian 2014-10-30 12:12:08