Tuesday, May 30, 2006

How to set up thinclient in Linux


Thin Client How to by Vaibhav Gupta

How to set up Thintux Server
You need to setup dhcp server and copy thintux folder on the server.
Setting up dhcp server
a. Make dhcpd configuration file :-> /etc/dhcpd.conf
b. Starting dhcpd :-> /etc/init.d/dhcpd start

Configuring dhcpd.conf Manually:-
1. Set subnet,netmask,router and range of IPs.
2. Set Thintux session server address, resolution and color depth.
3. Detailed Information man dhcpd, man dhcpd.conf
4. Get Sample Configuration dhcpd.conf (For Linux)<a
href="thintux/dhcpd.conf" >[dhcpd.conf] </a>

Format of dhcp.conf :-
[code]
#global parameters...
subnet 10.105.0.0 netmask 255.255.128.0 {
# subnet-specific parameters...
range 10.105.13.101 10.105.13.210;
option routers 10.105.1.250;
option THINTUX_SESSION_SERVER "10.105.11.23";
option THINTUX_SCREEN_RESOLUTION "800x600";
option THINTUX_SCREEN_COLOR_DEPTH "8";
}
group {
#group-specific parameters...
host abc.iitb.ac.in {
#host-specific parameters...
}
}
[/code]
Configuring using config-dhcpd :-
1. http://config-dhcpd.sourceforge.net/

Start X Display Manager
1. vim /usr/X11R6/lib/X11/xdm/xdm-config
2. Comment the last line as below :-
!DisplayManager.requestPort: 0
3. Save and Exit
4. vim /usr/X11R6/lib/X11/xdm/Xaccess
5. uncomment the following line (By removing #)
#* #any host can get a login window
6. Save and Exit
7. Start xdm :-> xdm

Help and Debug :-
1. man xdm
2. Error Logs :-> /var/log/xdm-errors
or :-> /usr/X11R6/lib/X11/xdm/xdm-errors
3. X -query 10.105.11.23

Check tftp is enable on server
1. vim /etc/xinetd.d/tftp
2. Change the disable option to "no" as Below.
disable = no
3. Save file and exit
4. Restart xinitd

Copy /thintux folder in /tftboot on server
<a href="thintux/thintux.tgz" >[thintux][tgz] </a>

http://thintux.sourceforge.net/


How to setup thinclient
Client already contaning Linux OS
1. Copy "localdsk" as /root/thinlinux on Client <a
href="thintux/localdsk" >[localdsk][x86 boot sector] </a>
2. Modify /etc/lilo.conf
3. Run lilo
4. Restart the PC

Add following Entries to lilo.conf:-

default=thin-linux # Add or Modify this line for default Booting from N/w
image=/root/thinlinux
label=thin-linux
read-only


Client that doesnot contain Linux OS
For all the following steps you have to use Dos Bootable Floopy
containg fdisk, format, syslinux.com and linux image(thintux) [as
downloaded above].

1. Delete all partitions on Hard Drive using fdisk.
2. Execute :-> fdisk /mbr
3. Create 20MB Dos Partion and Make active
4. Reboot
5. Execute:-> Format C:
6. Execute:-> syslinux c:
7. Execute:-> copy linux c: The above file "linux" is same as "localdsk". Only the name is
changed in this case.
8. Remove Floppy and Reboot

For Debugging
1. Use tcpdump as
tcpdump -n port 7100
tcpdump -n port tftp

Links
http://thintux.sourceforge.net
http://www.dhcp.org
http://www.dhcp-handbook.com/dhcp_faq.html
http://syslinux.zytor.com
http://www.vlug.org/vlug/meetings/X-terminal_presentation/overview.html

C++ Programs [Interview]

Find the number which is odd number of times? [Interview]
Dated: Wed Dec 28 22:44:42 IST 2005

14 int findodd(int *n,int len)
15 {
16 int num=0;
17 for(int i=0;i<len;i++)
18 num^=n[i];
19 return num;
20 }

How would u sort of 0s and 1s in just single pass? [Interview]
Dated: Wed Dec 28 22:27:42 IST 2005

1 void sort_01 (int *n,int len)
2 {
3 int i=0,j=len-1;
4 while(1){
5 while((!n[i])&&(i<len)) i++;
6 while((n[j])&&(j>-1)) j--;
7 if(i>=j) break;
8 n[i]=~n[i]&1;
9 n[j]=~n[j]&1;
10 i++;j--;
11 }
12 }

Find all possible splits for any given number n. [Interview]
Dated: Wed Dec 28 21:33:48 IST 2005

Init : int array[5]={0,0,0,0,0};
Function Call : split(array,5,0);

1 void split(int *n,int count,int len)
2 {
3 if(count==1) {
4 int i;
5 for(i=0;i<len;i++)
6 printf("%d+",n[i]);
7 printf("%d\n",n[i]+1);
8 return;
9 }
10 else {
11 n[len]+=1;
12 split(n,count-1,len);
13 split(n,count-1,len+1);
14 n[len]-=1;
15 }
16 return ;
17 }

WAP to check a integer (as binary string) is pallindrome? [Interview]
Dated: Wed Dec 28 18:27:43 IST 2005

1 bool panlindrome(unsigned long i)
2 {
3 if(!(i&1)) return false;
4 unsigned long t=i,rev=1;
5 t>>=1;
6 while(t) {
7 rev<<=1;
8 if(t&1) rev |=1;
9 t >>=1;
10 }
11 if(rev==i) return true;
12 return false;
13 }

Find the number of ones in an integer? [Interview]
Dated: Wed Dec 28 18:17:14 IST 2005

1 unsigned noofone(unsigned long i)
2 {
3 int count=0;
4 while(i) i=i&(~(i&(~i+1))),count++;
5 return count;
6 }

WAP to convert a given integer to octal number? [Interview]
Dated: Wed Dec 28 17:45:04 IST 2005

1 #include<stdio.h>
2 void int2octal (unsigned long i)
3 {
4 if(i) {
5 unsigned long o = i&7;
6 i>>=3;
7 int2octal(i);
8 printf("%d",o);
9 }
10 else printf("0");
11 }

How to reverse a singly-linked list? [Interview]
Dated: Tue Dec 27 06:49:35 IST 2005

1 node* reverse_list(node *list)
2 {
3 node *rev=NULL;
4 while(list !=NULL) {
5 node *t = list->next;
6 list->next = rev;
7 rev = list;
8 list = t;
9 }
10 return rev;
11 }

How To Speed Up Firefox [Howto]

Here's something for broadband people that will really speed Firefox up:

1.Type "about:config" into the address bar and hit return. Scroll down and
look for the following entries:

network.http.pipelining network.http.proxy.pipelining
network.http.pipelining.maxrequests

Normally the browser will make one request to a web page at a time. When you
enable pipelining it will make several at once, which really speeds up page
loading.

2. Alter the entries as follows:

Set "network.http.pipelining" to "true"

Set "network.http.proxy.pipelining" to "true"

Set "network.http.pipelining.maxrequests" to some number like 30. This means
it will make 30 requests at once.

3. Lastly right-click anywhere and select New-> Integer. Name it
"nglayout.initialpaint.delay" and set its value to "0". This value is the
amount of time the browser waits before it acts on information it recieves.

If you're using a broadband connection you'll load pages MUCH faster now!

Vaibhav.

How to Export sound in Linux [Howto]

Exporting sound :-

Run 'artsd -n -u -p 5001' on system on which u want to hear sound.
Run 'export ARTS_SERVER=ip_of_system_on_which_sound_it_to_be_heard:5001'
on system where sound application will be run (like mplayer)
Run 'mplayer -ao arts soundfile.mp3'

Monday, May 29, 2006

Vim Movements

Moving Around
k (up),
h(left) l (right).
j (down)
(Ex 5k,j,3l )

Word Movement
w (Forward Word Movement Ex. f,5f )
b (Backword Word Movement Ex. b,2b)
e (Forward Word Movement at the end of word Ex. e,3e )
ge (Backword Word Movement at the end of word Ex. ge,3ge )

Moving to the Start or End of a Line
$(End Of Line Ex. $,2$)
^(Start Of Line Ex. ^,3^)

Searching Along a Single Line
f<Charcter> (Searching Charcter Forward Ex. fa, 2fv)
F<Charcter> (Searching Charcter Backword Ex. Fg,2Ft)
t<Charcter> (Search till Forward )
T<Charcter> (Search till Backword)

Moving to a Specific Line
<Line No.>G (Go to Line No.)
CTRL-G (Where I am in the File)
g CTRL-G (Count col, line, words and bytes)
CTRL-O Jump to previous location.
<TAB> Jump to next location (line 10).

Where are you in File
:set number
:set nonumber

Scrolling Up and Down
CTRL-U (scrolls up half a screen of text.)
CTRL-Y (scrolls up a line of text.)
CTRL-B (scrolls up a entire screen at a time.)
CTRL-D (scrolls down half a screen of text.)
CTRL-E (scrolls down one line.)
CTRL-F (scrolls down one screen of text.)
z<Enter> (screen line on the top)
88z<Enter> positions line 88 at the top.
zt (Leaves the cursor where it is.)
z- (scrolls line to the end of the screen)
zb (Leaves the cursor where it is)
z. (Center of the screen)
zz (Leaves the cursor where it is .)

:set scroll=10
:set scrolljump=5
:set scrolloff=3

Deleting
x delete character under the cursor (short for "dl")
X delete character before the cursor (short for "dh")
dw (Delete Word Ex. dw,3dw,d3w,3d2w,d$,d^,df> )
dd (Delete Line Ex. dd,3dd)
D (Delete up to end of line. )(short for "d$")
diw delete word under the cursor (excluding white space)
daw delete word under the cursor (including white space)
dG delete until the end of the file
dgg delete until the start of the file

Arthemetic
CTRL-A Incrmenting Number (123, 0177, 0x1f,-98)
CTRL-X Decrementing Number

:set nrformats=""

Changing Text
cw (Change Word Ex cw,c2w)
C stands for c$ (change to end of the line)
s stands for cl (change one character)
S stands for cc (change a whole line)

The . Command
It repeats the last delete or change command.

Joining Lines
J (Join Lines to One. Ex J,3J)
gJ (Join Lines without Spaces)

Replacing Charcter
r<Charcter> (Replace Charater Under Cursour. Ex. ru,5ra,3r<Enter> )
R<Charcter>

Changing Case
~ (Change Case of Character Ex. ~,12~,~fq)
U (Make the text Uppercase)
u (Make the text Lowercase)
g~motion (It does not depend on tildeop)
g~~ or g~g~ (Changes case of whole line)
gUmotion (All uppercase)
gUU (Changes to uppercase for whole line)
gUw (Changes to uppercase for word)
guw (Changes to lowercase for word)

How to set up ssh keys for Linux

How to set up ssh keys for Linux

1. Run "ssh-keygen -t dsa" on the machine which is the client.
Files Generated :
$(HOME)/.ssh/id_dsa : Your private Key
$(HOME)/.ssh/id_dsa.pub : Your public Key
You can enter empty passphrase.
Type can rsa and dsa for version 2 and rsa1 for version 1.
2. Now ssh into the server.You need to type password this time.
you have to transfer the publickey to server.
cd $(HOME)/.ssh
cat $(HOME)/.ssh/id_dsa.pub >> authorized_keys2

Note : Don't introduce any extra spaces, slashes or any other characters
If the file already exists, append the output of id_dsa.pub to EOF.

3. Repeat for Other machine if you want.
4. Now you can login without entering passwords.
On some machines, it might ask you to verify the host key,
but will happen only for the first time.

Changing MySQL root password

Changing MySQL root password

Sometimes you forget the root password, or something went wrong
modifying it. Here's how to reset the root password for mysql on a
Redhat Linux box:

[root@host root]#killall mysqld
[root@host root]#/usr/libexec/mysqld -Sg --user=root &
[root@host root]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1 to server version: 3.xx.xx
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> USE mysql

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> UPDATE user
-> SET password=password("newpassword")
-> WHERE user="root";
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> exit;
[root@host root]#killall mysqld

Then start MySQL again:

/etc/init.d/mysqld start

Makefile for c++ project

#---------------------------------------------------------------#
# Written By Vaibhav Gupta
#---------------------------------------------------------------#
# TARGETS:
# wire - default target
# dwire - debug target
# tag - For generating tag file
# clean/fresh - clean obj files.
#---------------------------------------------------------------#
#-- Customized variables
BINDIR=bin
OBJDIR=obj
SRCDIR=src
INCDIR=include

CC = g++
CWARN = -W -Wall -Wshadow -Wimplicit -Wreturn-type -Wcomment -Wtrigraphs -Wformat -Wparentheses -Wpointer-arith -Wuninitialized -O

CDBG = -g $(CWARN) -fno-inline
CFLAGS = -I$(INCDIR) $(CDBG)
DFLAGS = -I$(INCDIR) -g $(CWARN) -fno-inline -DDEBUG=1

CTAG = ctags
CTAGFILE = filelist
# src, object and bin files
TGT=wire
#Debug Target
DBGTGT=dwire

HEADERS = $(INCDIR)/global.h

COMMONOBJS = $(OBJDIR)/BaseStation.o $(OBJDIR)/SubscriberStation.o
$(OBJDIR)/Packet.o $(OBJDIR)/Queue.o $(OBJDIR)/Global.o $(OBJDIR)/Simulate.o

OBJS = $(COMMONOBJS) $(OBJDIR)/main.o
DBGOBJS = $(COMMONOBJS) $(OBJDIR)/main.dbg.o

#-- Rules
all: $(TGT)
dbg: $(DBGTGT)

$(TGT): $(BINDIR)/$(TGT)
@echo "$@ uptodate"

$(DBGTGT): $(BINDIR)/$(DBGTGT)
@echo "$@ uptodate"

$(BINDIR)/$(DBGTGT): $(DBGOBJS)
$(CC) $(CFLAGS) -o $@ $(DBGOBJS)

$(OBJDIR)/%.dbg.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -DDEBUG=1 -c -o $@ $?

$(BINDIR)/$(TGT): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS)

$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -c -o $@ $?

.PHONY : clean depend fresh
tag :
find src/*.cpp include/*.h > filelist
$(CTAG) -L $(CTAGFILE)

clean :
-rm -f $(OBJDIR)/*.o $(PARSE_C) $(PARSE_H)
-rm -f $(SRCDIR)/*.output $(LEX_C)
-rm -f */*~ *~ core
-rm -f $(BINDIR)/$(TGT) $(BINDIR)/$(DBGTGT)

fresh : clean all

Picking a random quote or signature from a file [perl]

Generates a Random Signature from a signature file

script
--------

#!/usr/bin/perl
&pick_quote;
sub pick_quote {
my $path = "/usr/signature/";
my $sigfile = "$path/signature.txt"; # Signature FILE
open (SIGS, "< $sigfile" ) or die "can't open $sigfile";
local $/ = "%%\n";
local $_;
my $quip;
rand($.) < 1 && ($quip = $_) while <SIGS>;
close SIGS;
chomp $quip;
print $quip || "ENOSIG: This signature file is empty.\n";
}

Sample Signature File
---------------------------------

Signatures are a waste of bandwidth.
%%
Help stamp out signatures.
%%
'Calm down -- it's only ones and zeros.'
%%
According to my calculations the problem doesn't exist.
%%
A day for firm decisions!!!!! Or is it?
%%
A few hours grace before the madness begins again.
%%
A gift of a flower will soon be made to you.
%%
A long-forgotten loved one will appear soon.

Buy the negatives at any price.
%%

Linux Tips

------------------------------------------------------------------------------------
Who is SUPER USER in linux

awk -F: '$3 == 0{print $1,"superuser!"}' /etc/passwd
------------------------------------------------------------------------------------
How to get Environment for a process
If the process id is 920.

(cat /proc/920/environ; echo) : tr "\000" "\n"
------------------------------------------------------------------------------------
How to list files with their complete path
If 'childdir' is the name of directory.

find childdir -type f -printf "%AY%Am%Ad%AH%AM %p\n" : sort -r : gawk
'{print $2}'
------------------------------------------------------------------------------------
How to find open files in linux

find /proc -regex "/proc/[0-9]*/fd/.*" -ls
------------------------------------------------------------------------------------
Formatting man pages

man ls : col -bx > myfile.txt
------------------------------------------------------------------------------------
Finding the biggest files

ls -l : sort +4n
------------------------------------------------------------------------------------
Searching files for content

find / -name "filename" : xargs grep -n content
------------------------------------------------------------------------------------
Largest Directories

du -kx : egrep -v "\./.+/" : sort -n
-----------------------------------------------------------------------------------
List today's files only

ls -al --time-style +%D : grep `date +%D`
------------------------------------------------------------------------------------
Encrypt some plain text

perl -e 'print crypt("ke", "password");'
-----------------------------------------------------------------------------------
Look for unusual SUID root files

find / -uid 0 -perm -4000 -print
-----------------------------------------------------------------------------------
Look for unusual large files (> 10 Mb)

find / -size +10000k -print
-----------------------------------------------------------------------------------

Linux Command Line Tips

Linux Command Line Tips

http://www.pixelbeat.org/timeline.html

Vim Folding Tips

# folding : hide sections to allow easier comparisons

zf{motion} or {Visual}zf :Operator to create a fold.
zf'a : fold to mark
zF :Create a fold for N lines.
zd :Delete one fold at the cursor.
zD :Delete folds recursively at the cursor.
zE :Eliminate all folds in the window.
zo :Open one fold.
zO :Open all folds recursively.
zc :Close one fold.
zC :Close all folds recursively.
za :When on a closed fold: open it.and vice-versa.
zA :When on a closed fold: open it recursively.and vice-versa.
zR :Open all folds.
zM :Close all folds:
zn :Fold none: reset 'foldenable'. All folds will be open.
zN :Fold normal: set 'foldenable'. All folds will be as they were before.
zi :Invert 'foldenable'.

[z :Move to the start of the current open fold.
]z :Move to the end of the current open fold.
zj :Move downwards. to the start of the next fold.
zk :Move upwards to the end of the previous fold.

My vimrc: Open a c/cpp/java/perl programm. Press <F6> and see the power of
vim :-)

nmap <F6> /}<CR>zf%<ESC>:nohlsearch<CR>

Vaibhav.

How to Search in Google

How to Search in Google

1. allintitle: graph partition triangle
2. +("index of") +("/ebooks":"/book") +(chm:pdf:zip:rar) +apache
3. allinurl: +(rar:chm:zip:pdf:tgz) TheTitle
4. allinurl:config.txt site:.jp
5. allinurl:admin.txt site:.edu
6. "Index of /something"
7. filetype:doc site:edu

Links:-

http://www.googleguide.com/advanced_operators_reference.html
http://www.google.com/help/operators.html

Vim and HTML

HTML and vim Tips:

:runtime! syntax/2html.vim :convert txt to html
:%s#<[^>]\+>##g : delete html tags, leave text

My vim.rc : Type a word and press ",," without quote

imap <silent> ,, <ESC>"_yiw:s/\(\%#\w\+\)/<\1> <\\\1>/<cr><c-o><c-l>f>a

Vaibhav.

Extract links from a file [perl]

How to extractlinks from a file

#!/usr/bin/perl
use HTML::SimpleLinkExtor;
my $file = new HTML::SimpleLinkExtor();

# Extracts Links from a HTML File
# Written by Vaibhav Gupta guptav@cse.iitb.ac.in
$filename = $ARGV[0];
$url = $ARGV[1]; #base url else empty string

if($filename eq "" ) {
print "\nUsages: ./extractlink.pl filename.html\n";
exit ;
}

$file->parse_file($filename);
my @links= $file->a;
foreach $link (@links){
chomp;
print "$url$link\n";
}

Networking Hacks

How to chat without using talk

At Server side:
nc -l -p 5600 -vv
At client Side:
nc 10.100.116.37 5600

Here 10.100.116.37 is the ip of server. 5600 is the port.

How to transfer file with out using ftp

At Server Side:
nc -v -w 30 -p 5600 -l > filename.back
At Client Side:
nc -v -w 2 10.100.116.37 5600 < filename

How to mail using telnet

C: client
S: Server

C:telnet smtp.iitb.ac.in 25
S:220 smtp2.iitb.ac.in ESMTP
C:helo
S:250 smtp2.iitb.ac.in
C:mail from:<root@10.100.106.50>
S:250 ok
C:rcpt to:<guptav@cse.iitb.ac.in>
S:250 ok
C:data
S:354 go ahead
C:Subject: This is subject line.
C:hi vaibhav,
C:how r u? i m fine.
C:bye for now
C:vaibhav
C:.
S:250 ok 1095622024 qp 2471
S:502 unimplemented (#5.5.1)
C:quit
S:221 smtp2.iitb.ac.in
S:Connection closed by foreign host.

SMTP Commands

SMTP commands are ASCII messages sent between SMTP hosts.

*Command: Description
*DATA: Begins message composition.
*EXPN <string> : Returns names on the specified mail list.
*HELO <domain> : Returns identity of mail server.
*HELP <command>: Returns information on the specified command.
*MAIL FROM <host> : Initiates a mail session from host.
*NOOP : Causes no action, except acknowledgement from server.
*QUIT : Terminates the mail session.
*RCPT TO <user>: Designates who receives mail.
*RSET : Resets mail connection.
*SAML FROM <host> : Sends mail to user terminal and mailbox.
*SEND FROM <host> : Sends mail to user terminal.
*SOML FROM <host> : Sends mail to user terminal or mailbox.
*TURN : Switches role of receiver and sender.
*VRFY <user> : Verifies the identity of a user.