I usually check if a command succeeds or time out like this, which works just fine;
if timeout 30 someCommand; then
echo "we're good"
else
echo "command either failed or timed out"
fi
But with my new script which works with loops and variables, this simply doesn't work as expected;
wallets=/usr/local/bin/*-cli
for i in $wallets; do
current_blocks=$(timeout 30 $i getblockcount)
if $current_blocks; then
echo "we're good"
else
echo "command either failed or timed out"
fi
done
how can I fix this?
$( ..)you are storing the output to some variable not the return codecurrent_blocks=$(timeout 30 $i getblockcount)you can docurrentBlocksRetCode=$?to get the return code, thenif [[ $currentBlocksRetcode -eq 0 ]]then you are good.we're goodeven if the command fails or time outs.