Wednesday, April 6, 2011

bash-fu: seq

so on my local cluster I have 9 nodes, and every now and then I need to clean up the mess that my SGE jobs create, or collect the logs or whatsoever. So I want to ssh and execute the same command on each machine. the node names are 'compute-0-[0-9]+'.

enter seq. seq will generate a sequence of numbers in the given range. Using the xargs, I write
seq 1 9 | xargs -L1 -Ix sh -c "ssh compute-0-x ' do something awesome'".

magic is easy :)

Saturday, April 2, 2011

bash as a functional language.

Following the previous posting on similarity between the functional staple map(), and xargs, I was looking more deeply if we can consider bash programming a functional language. In the xarsg example I used before, I used the sh -c trick, which can be said is analogous to eval function in any functional language. Exactly the same can be achieved using the back-tick syntax, give a string as an input, and get the result of evaluation.

So now we have eval, and therefore closures and 'sorta' anonymous functions which can be passed around as strings and evaluated using eval. the pipes tie this all together, allowing to pipe the results from one function to another.

What else do we need to call a language functional? thinking...