From: Rahul on
Is there a nice way to run a command with a timeout around it?

For example sometimes I query ~100 servers about their status using a
command like so:

for i in $(seq 1 99); do ipmitool 172.16.0.${i} status; echo $i ; done

But let's say one server (say, 172.16.0.4) is hung or unresponsive. Then
the loop never goes beyong this to 172.16.0.5 etc. Ideally, I'd like the
loop to wait for, say, 10 secs. and if no response then go to the next
index in the loop.

Any nice way to do this? Ideally on the bash command line. But I am also
open to other ideas.

Of course, had ipmitool an option "timeout" this problem would have been
better addressed. But the way things stand if a server is unresponsive then
ipmitool just waits infinitely.


--
Rahul
From: Bit Twister on
On Fri, 9 Jul 2010 22:54:49 +0000 (UTC), Rahul wrote:
> Is there a nice way to run a command with a timeout around it?
>
> For example sometimes I query ~100 servers about their status using a

Personally, I use ping with a -w switch in my scripts. man page snippet.

-w deadline
Specify a timeout, in seconds, before ping exits regardless of
how many packets have been sent or received. In this case ping
does not stop after count packet are sent, it waits either for
deadline expire or until count probes are answered or for some
error notification from network.
From: Rahul on
Bit Twister <BitTwister(a)mouse-potato.com> wrote in
news:slrni3fah4.j9q.BitTwister(a)wb.home.test:

>> For example sometimes I query ~100 servers about their status using a
>
> Personally, I use ping with a -w switch in my scripts. man page snippet.
>
> -w deadline
>

True. Ping works. But there's other stuff I monitor with IPMI as well. e.g.
sensor temperatures, voltages etc.

--
Rahul
From: mjt on
On Fri, 9 Jul 2010 22:54:49 +0000 (UTC)
Rahul <nospam(a)nospam.invalid> wrote:

> Is there a nice way to run a command with a timeout around it?
>
> For example sometimes I query ~100 servers about their status using a
> command like so:
>
> for i in $(seq 1 99); do ipmitool 172.16.0.${i} status; echo $i ; done
>
> But let's say one server (say, 172.16.0.4) is hung or unresponsive.
> Then the loop never goes beyong this to 172.16.0.5 etc. Ideally, I'd
> like the loop to wait for, say, 10 secs. and if no response then go
> to the next index in the loop.
>
> Any nice way to do this? Ideally on the bash command line. But I am
> also open to other ideas.

Some may say this suggestion is over the top, but I'd write
a simple "c program" to launch multiple threads, each one
responsible for each "machine ping", then offer different
methods of communicating the results. Ask me how I know :)

I did this years ago for the same reason ... I had it send
me a text message for any machine(s) not responding.

--
The average woman would rather have beauty than brains, because the
average man can see better than he can think.
<<< Remove YOURSHOES to email me >>>

From: marrgol on
On 2010-07-10 01:17, Rahul wrote:
>> use ping with a -w switch
>>
> True. Ping works. But there's other stuff I monitor with IPMI as well.

Then send one ping with the deadline, and if it succeeds continue
with ipmitool:

for i in $(seq 1 99)
do
ping -c 1 -w 10 172.16.0.${i} >/dev/null 2>&1 \
&& ipmitool 172.16.0.${i} status
echo $i
done

--
mrg