Wow, okay what happened to the last few months? It has been a crazy start to the year and I don't feel
like I've had any time to try and investigate new and cool things or smash around with systems and get
blogging with what I've been doing.
It's been a busy time with work trying to recruit new people, push forward with updating systems and rolling out services. But one thing I have been doing lately is a lot of smashing around with Bash scripts and finding cool little flags or options in system commands.
If you're using Linux or Mac or you work on Linux-based systems, it's inevitable that you will at some stage require some scripts to undertake the work you need. If you've never before created some scripts to do your bidding, you're missing out on some very cool and useful functionality.
I run a helper application on my mac that can run a variety of tasks. From the command line I can run a script with some options and do things like: fire up Chrome windows with specific URL's; launch SSH sessions to specific systems; purge local DNS cache; Run a backup to external drives...
"Wow, that's so lazy!" I hear you moan. Trust me, when you're at 3am and you need to open six browser windows to specific servers on your fleet when you're on call and your eyes aren't quite open - you'll thank me later!
In bash scripts, just as with other languages, you can create functions that can be called - e.g.
Handy functions that I throw in my local mac script:
I recently had a client throw a gargantuan quantity of data into a single directory. This caused a
problem for deriving the contents of the folder ( lovely overflow and refusal to output directory
Now, one of the things that ls does is try to enumerate all the data and then alphabetically sort the output. This can cause it to have major issues with large quantities of files.
To get around this issue, my colleague discovered a forgotten switch that stops ls from doing the ordering task:
I had to move a whole bunch of files from one location to another where there were large quantities
of files - so the head command helped out:
Find files in directories recursively and move them to a single directory:
There are probably a whole bunch of other items I've used lately and forgotten how useful they are but figured I'd document some for when I next go "I'm sure there's an easier way to do this" in a month or two's time! ;-)
Cheeky Solr Grabber
KS2 Computer Club