Tuesday, July 24, 2007

Zgrep

To grep through archived gz files etc , instead of unzipping and then grep
you can use this tool zgrep
say for eg.
zgrep anonymous /var/log/xferlog.*

Monday, July 23, 2007

Scripting woes

I was trying to get a perl script with a sed oneliner called from within the perl script..
It started itching me when I tried inserting a few leading spaces into the replacement text in sed.
Here's the snippet

my $mask = '255.255.255.0';
foreach my $device (sort keys %ifaddrs) {
unless ($ifmasks{$device}) {
$t = `sed -e "/255.255/ a\ \\\t '$device' => '$mask'," $deffile > $deffile.new ` ;
print $t ;

The leading tab never worked properly till we finally preceded \t with two escape sequences- one each for the perl and sed parsing.
With the third one , it finally worked. The better part of it was that the perl variables worked well in sed ..i.e. they were parsed by perl before passing it on to sed..well, in another way thats what screwed me when it came to the white spaces..Anyway all working now, here's the full script...
#!/usr/bin/perl
#use strict;
use warnings;
my $file = shift @ARGV;
my $check = 0;
print "\nchecking $file\n";
check_arrays($file);
sub check_arrays {
my $deffile = shift;
#my (%ifaddrs, %ifmasks, %bootproto, %onboot);
require "$deffile";
my $mask = '255.255.255.0';
foreach my $device (sort keys %ifaddrs) {
unless ($ifmasks{$device}) {
print "$deffile def file does not have ifmasks for $device\n";
$t = `sed -e "/255.255/ a\ \\\t '$device' => '$mask'," $deffile > $deffile.new ` ;
print $t ;
}
unless ($bootproto{$device}) {
print "$deffile def file does not have bootproto for $device\n";
}
unless ($onboot{$device}) {
print "$deffile def file does not have onboot for $device\n";
}
}
undef %ifaddrs;
undef %ifmasks;
undef %bootproto;
undef %onboot;
}

Saturday, July 14, 2007

A few tips

Running multiple X sessions
On your login prompt. Insert your login and password and then execute:
startx -- :1
to get into your graphical environment.
To go back to the previous user session, press Ctrl+Alt+F7, while to get yours back press Ctrl+Alt+F8.
The keys F1 to F6 identify six console sessions, while F7 to F12 identify six X sessions.

Thursday, July 12, 2007

DVD Ripping

I've been ripping a few DVDs of late and I've got this wonderful tool
HandBrakeCLI http://handbrake.m0k.org/
Its really cool and simple.You might need to get the right libraries installed but its really simple to use. Just remember to select your subtitle no..the default is none..

Just happened to get this strange error today while playing with one of the servers
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
was wondering what it was...and finally turned out that I was installing an rpm sitting in a directory which the rpm moved and I ended up getting the error :)

Tuesday, July 03, 2007

Screen tips

For scrolling back on screen
press Ctrl A Esc
then Ctrl U

For down Ctrl D

To switch windows in screen
Ctrl A 1 , 2 , 3 etc