echo "select 1 from dual;" | sqlplus user/password@database | mail -s "Result of your query" email@example.com
I love Unix, me.
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.
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.
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.
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. ;-)
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.
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.
So far, so futile. :-(
Aiee, killing interrupt handler!
In interrupt handler - not syncing.
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.