[Nottingham] Re: AAaaargh! Bash and & and ; and () ...

Martin martin at ml1.co.uk
Sun Jan 29 22:15:28 GMT 2006


Michael Erskine wrote:
> Martin wrote:
> 
>> [...shedloads of bash complexity :) ...] 
> 
> 
> I'm wondering what resistance you have to using a programming language 
> that would make this task more straightforward. There's plenty of tools 
> out there that are fit for the job.

Good question...

No resistance at all other than the history of incremental evolution!

The script is just sending out and collating pings times to various 
machines. There's smokeping for that job but I much preferred the output 
of mrtg and already had that running with snmp. So, its all just a 
series of customised 'add-ons'.

The "Computer Science Geekie" bit was to add accurate interval timing 
between initiating the next round of pings rather than just letting the 
pings free run in a loop. I greatly dislike the inaccuracy and 
inefficiencies of polling, so using named pipes (mkfifo) to force a loop 
wait until a timed "ok" is written looked to be ideal.

(It also meant that I kept a single process flow in case the pings 
overran the loop interval, in which case the loop is timed by the 
slowest ping. This automatically avoids reentering the code if something 
like cron for example was set too fast.)

Little did I realise the (human) time penally of blundering into the 
bash foibles of creating multiple child processes for what I thought was 
so simple!

At least I've learnt about the timing race problem ("Interrupted System 
Call") for closing a file descriptor inside a loop which is then to be 
reused on the next loop iteration! Hopefully someone equally perplexed 
might stumble across this thread to see the solution.

I could convert it all to C or C++ but it would still remain mainly 
calls to "ping", "mv" and "sort" ... One advantage is that bash makes 
the code immediately human visible.


We could have a contest to see what the same routine looks like in perl 
and C (or other favoured codings) and compare the pros and cons of the 
methods... Yes?

Cheers,
Martin

-- 
----------------
Martin Lomas
martin at ml1.co.uk
----------------



More information about the Nottingham mailing list