Tuesday, February 10, 2009

Stupid Unix tricks that save me

I multitask a lot during my day, just the nature of having both development responsibilities and support responsibilities. One of the tricks I use a lot is using various shell scripting tricks interactively. For instance.

sleep 600; /home/duncanw/workspace/qavod3/qavod-ccor-m.sh

That silly line will sleep for 5 minutes then run my qavod-ccor-m.sh script. So I can restart a server by hand, then run the above command. It will wait 5 minutes for the startup to complete and then execute my little script. So I don't have to pay attention, and I don't get impatient about the 5 minute wait.

I also execute a lot of interactive for loops in bash. For instance

for site in `cat /tmp/x`
ssh $site

When I need to check some arbitrary list of servers for some condition, I can just type that in above interactively and voila, I won't loose track of where I am. I will check all the servers in the list and the shell keeps track for me.

I know this isn't rocket science but this type of off the cuff interactive shell scripting helps me a ton. I do similar tricks with python interactive shells, mostly to do math and convert epoch timestamps into wall clock times.

No comments: