April 30, 2008

Automated scripts

This is a simple and very simple script! Not even worth mentioning as it does nothing but utilizes another command.Still let it be here.

#/bin/bash
df -H|awk 'BEGIN{i=0;j=0} $1~/\/dev/ \
{if($4~/M$/){i=i+($4/1000)}else{i=i+$4};j=j+$2} \
END{print"Free space:"i" GB";print"Total Space:"j" GB";print"Percentage Free:"i/j*100"%"}'


Its self explaining enough.
Sample output is:

vivek@vivek-desktop:~$ space
Free space:31.6 GB
Total Space:252 GB
Percentage Free:12.5397%
vivek@vivek-desktop:~$


Here is the content of my /etc/init.d/bootmisc.sh
I guess here I can add some scripts I need to run.

#!/bin/sh
### BEGIN INIT INFO
# Provides: bootmisc
# Required-Start: $local_fs hostname $remote_fs
# Required-Stop: $local_fs
# Default-Start: S
# Default-Stop:
# Short-Description: Miscellaneous things to be done during bootup.
# Description:
### END INIT INFO

PATH=/usr/sbin:/usr/bin:/sbin:/bin
[ "$DELAYLOGIN" ] || DELAYLOGIN=yes
. /lib/init/vars.sh

do_start () {
#
# If login delaying is enabled then create the flag file
# which prevents logins before startup is complete
#
case "$DELAYLOGIN" in
Y*|y*)
echo "System bootup in progress - please wait" > /var/lib/initscripts/nologin
;;
esac

# Create /var/run/utmp so we can login.
: > /var/run/utmp
if grep -q ^utmp: /etc/group
then
chmod 664 /var/run/utmp
chgrp utmp /var/run/utmp
fi

# Set pseudo-terminal access permissions.
if [ ! -e /dev/.devfsd ] && [ -c /dev/ttyp0 ]
then
chmod -f 666 /dev/tty[p-za-e][0-9a-f]
chown -f root:tty /dev/tty[p-za-e][0-9a-f]
fi

# Update motd
uname -snrvm > /var/run/motd
[ -f /etc/motd.tail ] && cat /etc/motd.tail >> /var/run/motd

# Save kernel messages in /var/log/dmesg
if which dmesg >/dev/null 2>&1
then
savelog -q -p -c 5 /var/log/dmesg
dmesg -s 524288 > /var/log/dmesg
chgrp adm /var/log/dmesg || :
elif [ -c /dev/klog ]
then
savelog -q -p -c 5 /var/log/dmesg
dd if=/dev/klog of=/var/log/dmesg &
sleep 1
kill $!
[ -f /var/log/dmesg ] && { chgrp adm /var/log/dmesg || : ; }
fi

# Remove bootclean's flag files.
# Don't run bootclean again after this!
rm -f /tmp/.clean
}

case "$1" in
start|"")
do_start
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
# No-op
;;
*)
echo "Usage: bootmisc.sh [start|stop]" >&2
exit 3
;;
esac

:

April 12, 2008

My first perl program


#!/usr/bin/perl

# chess.plx

use warnings;

use strict;



my @chessboard;

my @back = qw(R N B Q K N B R);

for (0..7) {

$chessboard[0]->[$_] = "W" . $back[$_]; # White Back Row

$chessboard[1]->[$_] = "WP"; # White Pawns

$chessboard[6]->[$_] = "BP"; # Black Pawns

$chessboard[7]->[$_] = "B" . $back[$_]; # Black Back Row

}



while (1) {

# Print board

for my $i (reverse (0..7)) { # Row

for my $j (0..7) { # Column

if (defined $chessboard[$i]->[$j]) {

print $chessboard[$i]->[$j];

} elsif ( ($i %2) == ($j %2) ) {

print "..";

} else {

print " ";

}

print " "; # End of cell

}

print "\n"; # End of row

}



print "\nStarting square [x,y]: ";

my $move = <>;

last unless ($move =~ /^\s*([1-8]),([1-8])/);

my $startx = $1-1; my $starty = $2-1;



unless (defined $chessboard[$starty]->[$startx]) {

print "There's nothing on that square!\n";

next;

}

print "\nEnding square [x,y]: ";

$move = <>;

last unless ($move =~ /([1-8]),([1-8])/);

my $endx = $1-1; my $endy = $2-1;



# Put starting square on ending square.

$chessboard[$endy]->[$endx] = $chessboard[$starty]->[$startx];

# Remove from old square

undef $chessboard[$starty]->[$startx];

}





This is just a simple chess,where white player can move around anywhere doing anything.Not victory conditions set.Please do try it.
I remade it from an original chess program.

April 05, 2008

Pidgin rocks!!!

PIDGIN




This is about my favorite IM,Purple Pidgin.I had used GAIM messenger previously in Linux.As with most of the Linux Apps, it had lots of shortcomings,in spite of which we all loved and used it ..mainly because that was the best one available.

Then with the latest Ubuntu came Pidgin.The base install is clean and looks similar to GAIM,only that the interface looks more clean and attractive.Also with pidgin,I set up my google and yahoo accounts and hence was more useful to me than my GAIM,for which I didn't know how to setup up google account.



Why I am suddenly blogging about this software is because last week I was bored and had nothing to do.... and my bandwidth was pretty low.So I just opened up Pidgin and started checking out all options and configurations.I got curious with the plugin list which is quite interesting.There was a mention about more plugins available on the site.

After 2 am that day...I searched for pidgin plugins...got a few sites and went through the plugins...some where mind-blowing and some were the features that other IMs sport.I had also checked the Google Summer of Code page for Pidgin,there were some interesting plugins like Musictracker which puts currently playing music on status message.Soon I had found about 10 plugins and downloaded and installed each.


The main one I did was the best in the pack.It gives a script for my site.I can put up a chat window on any site,with the javascript.Then I have to configure my client with a new Account(all details from that site itself).I configured it and tried it soon...it was simply amazing...I really love it.Many of my pals have already tried it.Its here in this blog...please do try if I am online.

I also installed some more plugins from the Synaptic Package Manager.I didn't get a chance to try them though.Today I found all of them installed and I just went through the Plugins list..whoa..and I enabled a few.I will list the ones I liked and am using and describe a few.

Chat colours,autocomplete(really cool),Off the Record,Invisibility,Away Time Setter,Psychic Mode,Availabilty Probability,GUIfications,Hotkeys,New Smileys,Notifications,Music Messaging and Mouse Gestures.

Invisibility and Off the Record
The really cool features available in most IMs...now in Pidgin too

Psychic Mode
Whenever a user starts typing a new conversation...I get a funny message..saying "I feel a disturbance in the force..."so i can react before they do....helps startle my buddies...

Availability Probability
This I don't know how it works.It is supposed to give probability of being available for each contact.... :P

GUIfications
Cool pop ups and notifications when someone types or leaves or returns

Music Messaging
Allows people work on same score of music simultaneously..not much use to me..but cool

Mouse Gestures
Allows many operations by mouse gestures..cool

There are many more cool features about Pidgin and many more to come.Anyway pidgin has become more fun than gtalk.It just lacks in file transferring,voicemails and ability to remove status messages.

Pidgin Site
Also there is a command line version called Finch.Its really cool..do try it out.
Finch

April 04, 2008

My love...ma keyboard



It happened so that I was going to sleep and decided that as it was 1.30am,I should login and then put some downloads.DSP preparation is scheduled.
But what awaited me were dead keys on the keyboard,quite a lot of them.I had struggled with them earlier in the day,but now it wasn't going away,I couldn't even login....what else could be a worse situation for a terminal savvy person???Gosh...I was worried whether I would need to run to the shop tomorrow to buy a new keyboard.
I did some google search(carefully using other keys) and most sites asked me to replace keyboard if such dead keys occur frequently.
Umpgh....I had a sudden impulse and quickly shutdown the system and grabbed a screwdriver.I tried removing the dead keys,but the keys around didn't allow....so I set to remove each and everyone...anyway I hadn't cleaned it after it was bought 2 yrs back.
So I set to the task of popping out key after key without bothering to remember their positions,I was fully enjoying it.It was fun...some keys flew away and had to be picked up.Only after removing majority of the keys did I realize that I should have noticed their positions...oh well..I didnt expect the dead keys to be fixed..but then I wanted to continue with this work.Also in the process of removal,I accidentally broke the Space key partially which was working very well and the most used key.
Sigh...

Then I set to cleaning up the dirty board with some hankie..it was fun...2mins...job done.Now remained the huge task of replacing the keys to the correct position and sleep was rocking me like anything....yawn..even now...
And I put those parts back which I knew well(thats around 80%).Rest was guess work.I had to try some keys few times to get it right.I had my doubts whether the keys would respond.
So I connected the fully set keyboard and powered up to Windows.I did some type tests and found 2-3 misplacements.I was relieved only when I logged into Ubuntu,put downloads and typed this in...love u my keyboard.
I am keyboard savvy person in love with the terminal,and only when the keyboard was in a dangerous situation did I felt the real pain.I was so worried about what I would without my black beauty...the one that helps me conquer the terminal...hehe...