May 01, 2008
Emailing yourself the result of a query
echo "select 1 from dual;" | sqlplus user/password@database | mail -s "Result of your query"

I love Unix, me.

Posted by Simon Brunning at 02:06 PM | Permalink | Comments (3)
February 18, 2008
Top-and-tailing log files

Some of our log files are huge - I have a 10 GB file on my HDD right now. These files are unwieldy to say the least, and you usually have a good idea as to the time in which a particular problem occurred, so it's often handy to be able to chop out a specified time range. I keep forgetting how to do this, and re-inventing the process. So, here for my own benefit at a couple of methods.

The hard way

From the bash shell:

wc -l your.log

This will count the lines in your file.

grep -n 12:00: your.log | head -n 1

This will give you the line number of the 1st line containing "12:00:" - in this example, I want log entries starting at midday, so this is the first line that I want.

grep -n 12:10: your.log | tail -n 1

This will give you the line number of the 1st line containing "12:10:" - in this example, I want log entries up to ten past twelve, so this is the last line that I want.

tail -n $[total-first] your.log | head -n $[total-last] > your_focused.log

Replace first, last and total with the values you got above, and you'll end up with a file containing only the time range that you wanted. (If you only want to look at the file once, you can just pipe into less or whatever rather than piping into an output file.)

The easy way

python -c "import itertools, sys; sys.stdout.writelines(itertools.takewhile(lambda item: not '12:10:' in item, itertools.dropwhile(lambda item: not '12:00:' in item, open('your.log'))))" > your_focused.log

Same thing, only this will read through the file just once.

Now, I'm fully expecting someone to come and tell me the real easy way. ;-)

Posted by Simon Brunning at 12:25 PM | Permalink | Comments (16)
November 30, 2007
Fear of Flying

Hey - did you know you can run less directly over a gzipped file? Cool.

less /resin-apps/r2apps/log/r2frontend.log.2007-11-29.gz

Posted by Simon Brunning at 04:00 PM | Permalink | Comments (5)
November 21, 2007
Subversion Log Filtering

So, Annabel was complaining that she couldn't see a log of just her Subversion revisions along with details of the files that have changed from the command line. Shock horror - something you can do from Tortoise that you can't easily do from the shell!

(If you don't care about seeing a list of the files that have been changed, you can just do svn log | grep -A2 sbrunning | less, but adding the -v option turns the output to gibberish.)

Clearly I wasn't going to to let that stand, so I knocked up a very quick script. Then proceeded to over-engineer the snot out of it. (In my own time I must add.)

You can filter by author or by checkin message, with regexps. You can also reverse the output and see the latest checkin last, which is handy if you are only want to see the most recent checkins and don't want to pipe the output to less.

Get it here: svnlog (syntax highlighed - loving that Django TextMate theme) or svnlog (text). Requires Python 2.5. Works on Mac & Linux, probably on Windows too if you give it a .py suffix.

Posted by Simon Brunning at 06:05 PM | Permalink | Comments (4)
September 30, 2004

Andy's always banging on about Vim. And having seen him using it, I have to admit, he can go like stink using it.

Well, now I've got a console only Debian box that I'm working on, so I'm having a go. I don't like it. It keeps beeping at me.

I've also just wasted 3 hours trying to get PHP 4 running under Apache 2, only to find that it was all going Pete Tong because I'd installed the wrong package - libapache-mod-php4 rather than libapache2-mod-php4. Doh! Still, it's all going now, and it's all been very educational. I'm relearning the knack of getting around a command line, I'm learning some Linux commands and a bit of Bash, and if I'm not exactly becoming familiar with Vim, I'm no longer utterly bewildered.

Posted by Simon Brunning at 04:26 PM | Permalink | Comments (9)
September 29, 2004
Goodbye Woody, hello Sarge

So far, so futile. :-(

Plan A was to install Debian 3.0 r2 (Woody). The install process dies on the first reboot:

Aiee, killing interrupt handler!
In interrupt handler - not syncing.

I don't appear to be the only one with this issue - it appears that roadwarrior's hardware isn't compatable with Woody.

I know all the hardware can be made to work with Linux, though - Knoppix 3.6 drives everything fine. So, Plan B was to install from Knoppix, but that didn't work either:

Error: Formatting of  failed.

I'm not alone in having this problem, either, but I don't have a scooby what to do about it.

Now, I'm sure that if I were a Linux guru, I'b be pulling working bits out of Knoppix and stuffing them into Woody, but frankly, I wouldn't know where to start. So, Plan C is to grab Sarge and see how far I get with that.

Posted by Simon Brunning at 10:47 AM | Permalink | Comments (8)