Posts Tagged: bash

Bash to Python – Playing with CSV

In the past I have been too willing to use bash scripts for grepping and awking CSV files. The code snippet below is a starter for doing similar with python and while far from perfect, demonstrates calling another system command and manipulating strings:

Joining Multi-line Output with Paste


I was checking the memory on approximately 140 servers using ansible: ansible –user root -k -i servers.list -m shell -a “free -h; mysql” test but the output appears over several lines e.g. | SUCCESS | rc=0 >> total used free shared buffers cached Mem: 94G 44G 49G 59M 203M 4.6G -/+ buffers/cache: 39G 54G… Read more »

Batch Auto-Levels on Images

I had a thousand image files the kids had photographed when creating a stop motion video. An ‘auto-levels’ on many of the images was required to brighten them up so at the command line I used the following (with ImageMagick already installed of course): for FILE in $(ls /home/jonny/tmp/stopmotion/*.JPG); do convert -auto-level $FILE /home/jonny/tmp/stopmotion-fixed/$(basename $FILE)… Read more »