Tech

The New Look Tech Blog

Browsing Posts tagged bash

Colorful Bash Prompt

Custom Bash Prompt

As a sysadmin I spend a lot of time logged into other servers via SSH session. Often I have to log into systems I am not familiar with, and it is very easy to forget which one of the seven terminals that you are working in is actually logged into a remote machine.

I am certain I am not the only one that have accidentally shutdown a server while logged into it. Newby mistake, and never repeated due to this trick I learned.

continue reading…

Hey There.

This is a quickie update. It is Election Day for the Local Government Elections 2011 and results are just beginning to come in.

Real-time results are hard to come by, there is a twitter hashtag to follow namely #LGEResults, but that makes it hard to get an overview of what is going on, which party is in the overall lead.

Lucky for us the IEC has a results page at http://elections.org.za where you can search for the results you want to see and then download either a PDF or Excel spreadsheet to view the results. If you are not interested in the technical aspect of how I parsed the information from the IEC spreadsheet you can view the results HERE: http://g33q.co.za/parties

(Bear in mind that I am not affiliated with the IEC, and with none of the parties – I am just a computer guy who voted and want to see the election results)

The spreadsheet I use for input seems to be updated every 10 or 20 minutes at this stage.

If you want to find out how I actually did the scripting, read on:

It is a bit of a pain, so I wrote a bash script to automatically download the spreadsheet (the URL does not change between updates :-)) and then parse the information. You will need to install the package xls2csv that is relevant to your Linux distribution.

BEHOLD:

#!/bin/bash -x
rm National*
wget http://www.elections.org.za/content/LGEPublicReports/197/Detailed%20Results/National.xls
xls2csv National.xls > parties
awk -F"\"" '{ print $2 $7 $6}' parties | grep -f input > results

Predictably the output is ugly, but it at least gives me some information that I want.

Have fun playing with this one. I use: while sleep 5m; do ./scriptname; done to run it every five minutes, and in the script above I added a simple scp command to upload it to my server where you can view the results at http://g33q.co.za/parties if you want.

Cheers for now!

When Scripting Helps

3 comments

I ran out of space on my harddrive today. Serves me right trying to get along with a minimalistic 20gb /home partition.

Instead of trying to install or use a graphic tool to see what was using up the most space I decided I needed a quick script to get a picture of what is going on at /home.

Here is a quick overview of what I did…

continue reading…