Tuesday, September 25, 2007

Kool Linux Sites

http://www.slax.org/

: Get the Software

http://linuxhardware.org/ : Find about Hardware

http://www.linuxdevices.com/ : The Device part

http://tldp.org/LDP/sag/html/ : Do sysad

http://www.winehq.org/site/about : Want to plat games

http://newdata.box.sk/bx/hacker/ : Do something.

Vaibhav.

"When you guys actually learn something, come to me
and say, 'We learned something! We learned something!' and I'll
show you some cool stuff."

Wednesday, September 19, 2007

Tiddlywiki

http://www.tiddlywiki.com/

To set up:

wget http://www.tiddlywiki.com/empty.html
firefox file:///`pwd`/empty.html

Done.
<snip>
The easiest way to learn about TiddlyWiki is to use it! Try clicking
on various links and see what happens - you cannot damage
tiddlywiki.com or your browser.
</snip>

Thursday, July 26, 2007

VIM Tip

Convert any file to html file using vim from command prompt :
vim -c ":runtime! syntax/2html.vim | :wq | :q " <FILENAME>
File Created: <FILENAME>.html

Example:
vim -c ":runtime! syntax/2html.vim | :wq | :q " a.c

will create a file "a.c.html"

Friday, May 11, 2007

[Perl] Script to check stock

Script to check the stock and their graph :D
Uses finance.yahoo.com to get the graphs.

INPUT : stock.conf : contains stock symbol (one per line ) for each company.
You can find the symbols on http://finance.yahoo.com/lookup, if you don't know.

OUTPUT: Generates a html page that contains the information and graph for the given companies in stock.conf.

Requires: lynx
Usages: Put stocks.cgi and stock.conf in your cgi-bin directory. Open in firefox. Refresh to get latest info.
Note: you can also run the script from shell prompt and then redirect the output to a html file , then open this file in firefox :D But you need to run it every time you want the latest info.
# perl stock.cgi > mystocks.html
# firefox mystocks.html

Here are the files:

----- stocks.cgi ---
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
#Written by Vaibhav Gupta
################ Variables ######################
my $stockfile = "stock.conf";
my $tab_width = 3;
################################################

sub generatestockhtml () {
my @allfile = `cat $stockfile `;
my $toprint = "<table frame=box><tr>\n";
my $count=0;

foreach my $line (@allfile) {
chomp $line;
my ($firstchar) = ($line =~ /(.)/ );
my $stock=`lynx -source " http://finance.yahoo.com/d/quotes.csv?s=$line&amp;f=l1d1t1c6ohgn&e=.csv"` ;
my ($lasttrade,$lasttradedate,$lasttradetime,$change,$open,$dayhigh,$daylow,$name) = split(/,/,$stock);
#Not Printing lasttradetime
$toprint .="<td>
<b>$name</b> Trade Date = $lasttradedate <br>
Current: <font color=green>$lasttrade</font> Change:<font color=red> $change</font> <br>
Open: <font color=green>$open</font> High: <font color=green>$dayhigh</font> Low: <font color=green>$daylow</font>
<a href=\" http://ichart.yahoo.com/v?s=$line\">
<img src=\"http://chart.yahoo.com/c/0b/$firstchar/$line.gif\">
</a> <br>
<a href=\"http://finance.yahoo.com/q?s=$line&d=b\"> More Info</a>
</td>
\n";
$count++;
if($count % $tab_width == 0) {
$toprint .= "</tr><tr>";
}
}
$toprint .= "</tr></table>";
print $toprint;
}


print header("text/html"),
start_html("Vaibhav Gupta's Stock Page");
my $cur = CGI->new() ;
&generatestockhtml();
print end_html;

--- stock.conf --
goog
yhoo
msft
amzn
emc

Thursday, April 19, 2007

Trapping signals (^C and ^Z) in Bash

#!/bin/bash
#Script written by Vaibhav Gupta
#Trapping HUP TERM INT and ^Z in shell.

echo "Process ID = $$";
stty susp "" #Trapping CTRL-Z
trap 'echo "Trapping CTRL-C, TERM and HUP";' HUP TERM INT
echo

echo "Sleeping for some time"
for i in `seq 1 20`; do
    sleep 1
    echo -n "."
done
echo
stty susp "^Z"


Koool bash Functions


http://www.novell.com/coolsolutions/tools/18639.html

Tuesday, April 17, 2007

Script to exchange ssh keys

 1 #!/usr/bin/perl
2 use Expect;
3 #USAGE: ssh-key-exchange.pl <IP> <USERNAME> <PASSWORD>
4
5 my $ip = $ARGV[0];
6 my $login = $ARGV[ 1];
7 my $password = $ARGV[2 ];
8 my $private_key='/root/.ssh/id_rsa ';
9 my $public_key='/root/.ssh/id_rsa.pub ';
10 my $authorisedkeyfile='/root/.ssh/authorized_keys ';
11 my $timeout = 10;
12 my $aft = new Expect;
13
14 #Generate the public and private key on the local m/c A
15 if(!(( -e $public_key ) &&( -e $private_key ))) {
16 print "Generating the Public and Private Key:\n ";
17 @result=`ssh-keygen -t rsa -f /root/.ssh/id_rsa -P "" `;
18 #print @result;
19 }
20 #Copy the file to m/c B
21 print "Copying Public Key from A to B.\n ";
22 $aft->spawn("scp $public_key $login\@$ip:/tmp/");
23 $aft->expect($timeout,[ qr'\? $' , sub { my $fh=shift; $fh->send("yes\n"); exp_continue; } ],
24 [ 'Password: $',sub { my $fh=shift;$fh->send("$password \n");exp_continue;} ],
25 # '-re','\# $'
26 );
27 $aft->do_soft_close();
28
29
30 #Add Keys to authorised keys in B
31 print " Adding Keys to authorised key in B with IP=$ip,[ $login $password ] \n";
32 my $aft = new Expect;
33 $aft->log_file("/tmp/expect_log" ,"w");
34 $aft->spawn( "ssh $login\@$ip") or die "Cannot ssh to the machine \n";
35 $aft->expect($timeout,[ qr'\? $', sub { my $fh=shift;$fh ->send("yes\n"); exp_continue; } ],
36 [ 'Password: $',sub { my $fh=shift;$fh->send("$password\n ");exp_continue;} ],
37 '-re', '\# $'
38 );
39 $aft ->send("touch $authorisedkeyfile\n");
40 $aft->expect($timeout,'-re' ,'\# $');
41 $aft->send( "cat /tmp/id_rsa.pub >> $authorisedkeyfile\n");
42 $aft->expect($timeout,'-re', '\# $');
43 $aft->send(" exit\n");
44 $aft->do_soft_close();
45