Saturday, February 24, 2007

Updating perl modules from CPAN

Any modules available in CPAN could be easily updated to your system.
eg: to update the module "Bundle::ApacheTest"

perl -MCPAN -e 'install Bundle::ApacheTest'

Tuesday, February 13, 2007

Linux commands

unzip a tar.gz file
gzip -d httpd.tar.gz

untar a tar.gz2 file
tar -xjvf php.5.1.2.tar.bz2

untar a tar.gz file
tar -zxvf php.5.1.2.tar.gz

login as super user:
sudo su

install a package in debian Linux:
apt-get install gcc

search a package:
apt-cache search <patern>

updagte all:
apt-get update

chmod with group name and permission name.
chmod o+w file_name: adding write permission for others
chmod g+w file_name: adding write permission for group
chmod u+w file_name: adding write permission for user/owner

installing the kernel headers:
apt-get install linux-headers-2.6.12-9-386

copying file to other machine
scp <file_name> <user_id>@<ip_address>:<user_home>/dir
Note: this need ssh get installed.

Installing a debian package
dpkg -i skype.deb

list selected columns by formatting the output with awk
eg: to List only the 1st and 3rd column of ls -al output...
ls -al | awk '{print $1 $3}'

scan disk with FAT32 file system
fsck.vfat /dev/sda5
format disk
mkfs.vfat /dev/sda5 format disk.

format the output of 'top' command..
-press f to go to interactive commands.
-press W to write the current settings to a config file.
now, top will output according to your last written settings.

writing the output of top command to a file..
top -b > top_output.stats

Scroll in Linux with touchPad: IBM thinkpad T43

Add the last two lines to the file /etc/X11/xorg.conf

Option "EmulateWheel" # to get the trackpoint scrolling workin
Option "EmulateWheelButton" "2"

Eg:
Section "InputDevice"
Identifier "Configured Mouse"
Driver "mouse"
Option "CorePointer"
Option "Device" "/dev/input/mice"
Option "Protocol" "ImPS/2"
Option "Emulate3Buttons" "true"
Option "ZAxisMapping" "4 5"
Option "EmulateWheel" # to get the trackpoint scrolling working
Option "EmulateWheelButton" "2"

investigate system calls of a process

Sometimes it is important to monitor the system calls when a process is
running. by monitoring that, you can find what the system do when u see
an unusual delay.

syntax: strace -p <process ID>

sris@sris:~$ strace -p 9860

Process 9860 attached - interrupt to quit
select(0, NULL, NULL, NULL, {0, 702000}) = 0 (Timeout)
waitpid(-1, 0xbfaa0750, WNOHANG|WSTOPPED) = 0
select(0, NULL, NULL, NULL, {1, 0}) = 0 (Timeout)
waitpid(-1, 0xbfaa0750, WNOHANG|WSTOPPED) = 0
select(0, NULL, NULL, NULL, {1, 0} <unfinished ...>
Process 9860 detached


strace -pt <process_id> will prefix the time of the day with each sys
call printed.

sris@sris:~$ strace -t -p 9860
Process 9860 attached - interrupt to quit
02:00:26 select(0, NULL, NULL, NULL, {0, 855000}) = 0 (Timeout)
02:00:26 waitpid(-1, 0xbfaa0750, WNOHANG|WSTOPPED) = 0
02:00:26 select(0, NULL, NULL, NULL, {1, 0}) = 0 (Timeout)
02:00:27 waitpid(-1, 0xbfaa0750, WNOHANG|WSTOPPED) = 0
02:00:27 select(0, NULL, NULL, NULL, {1, 0} <unfinished ...>
Process 9860 detached

find and replace string in files

Find and replace in a single file - VI editor
-----------------------------------------------------------------
open vi editor
<http://www2.blogger.com/post-edit.g?blogID=26366170&postID=114535590336229335>
:%s/search_string/replace_string/g


Find and replace in multiple files
----------------------------------------------------

perl -pi -i 's/search_string/replace_string/g' *.txt

Installing ttf font in ubuntu linux

1. cd /usr/share/fonts/truetype
sudo mkdir myfonts
cd myfonts

2. cp /home/sris/downloads/vikatan.ttf .
sudo chown root.root *.ttf
sudo mkfontdir

3. cd ..
fc-cache

Tips for directory permission tips

* Removing x permission
If x permission is removed, system will prevent running 'ls', 'cd' to
the directory. Further can't copy files even with absolute path
sris@sris:~$ chmod -x protected_dir/
sris@sris:~$ ls -al protected_dir/
total 0
?--------- ? ? ? ? ? protected_dir/.
?--------- ? ? ? ? ? protected_dir/..

sris@sris:~$ touch protected_dir/test.a
touch: cannot touch `protected_dir/test.a': Permission denied

* Removing r permission
Can't do 'ls' but can do 'cd' and can copy files with absolute path

sris@sris:~$ chmod -r protected_dir/
sris@sris:~$ ls protected_dir/
ls: protected_dir/: Permission denied

sris@sris:~$ cd protected_dir/

sris@sris:~/protected_dir$ ls
ls: .: Permission denied

sris@sris:~/protected_dir$ cd ..

sris@sris:~$ touch protected_dir/test2.txt

sris@sris:~$ ls protected_dir/
ls: protected_dir/: Permission denied

Editing a debian binary for dependencies

1. mv prog_name.deb prog_name.deb.orig

2. mkdir prog_name.tmp

3. dpkg-deb --extract prog_name.deb.orig prog_name.tmp

4. dpkg-deb --control prog_name.deb.orig prog_name.tmp/DEBIAN
# Now use your favorite editor to edit the Depends line as required:

5. vi prog_name.tmp/DEBIAN/control
6. dpkg --build prog_name.tmp
7. mv prog_name.tmp.deb prog_name.deb

FTPS: ftp with ssl

lftp is a ubuntu linux tool, that support ftp through ssl.

If the ftps server running on 8990,

sris@sris:~/tmp$ lftp
lftp :~> open ftps://localhost:8990
lftp localhost:~> user sris password123
lftp sris@localhost:~> ls
-rw-r--r-- 1 sris sris 58 Feb 12 14:14 ftp_error.log
-rw-r--r-- 1 sris sris 104 Feb 12 14:14 httpsd.last
drwxr-xr-x 2 sris sris 4096 Feb 8 22:00 pub
drwxr-xr-x 2 sris sris 4096 Feb 8 22:00 uploads


* gftp is another tool. have to configure and install with openssl
./configure --with-openssl

ssh handshake without user interaction

1. create the identity.pub file, u can use dsa as well instead of rsa.
ssh-keygen -t rsa
provide the passphrase or keep it blank.

2. upload your id_rsa.pub file as ~/.ssh/authorized_keys to the remote host
eg: if u want to upload to a host called boo
scp ~/.ssh/id_rsa.pub boo:.ssh/authorized_keys

3. set your local and remote .ssh directory's permission to 700

4. set your remote authorized_keys file's permission to 600

5. set local id_rsa file's permission to 600

6. set local id_rsa.pub and known_hosts permission to 644

now you can just do 'ssh boo' without giving a login password. but if
you have given a passphrase it will ask for it.
you can save your passphrase by 'ssh-add' util.

7.
sris@sris:~/projects$ ssh-add
Enter passphrase for /home/sris/.ssh/id_rsa:
Identity added: /home/sris/.ssh/id_rsa (/home/sris/.ssh/id_rsa)

now you have the luxary to do
1. ssh boo
2. scp file.txt sris@boo:
without providing a passwd or passphrase.

8 If you add your key to the remote host's role account, you have to
concatenate your key with the existing ones.
cat id_rsa.pub >> authorized_keys

this will ensure other user's key will not be replaced by yours.

Packages useful when reinstall ubuntu linux

1. install codecs for media files.
download from "easy ubunty": http://easyubuntu.freecontrib.org/

2. Install gcc and build tools
apt-get install build-essential
apt-get install manpages-dev autoconf automake libtool
apt-get install flex bison gcc-doc g++

3. apt-get install mozilla-thunderbird

4. apt-get install openssh-server

5. apt-get install libqt3-mt (used for skype)

Generate SSL certificate

1. Create the private key
openssl genrsa 1024 > host.key

2. Create the certificate
openssl req -new -x509 -nodes -days 365 -key host.key > host.cert

3. Create .pem file
Some applications require the private key and certificate in a single
.pem file. then..
cat host.cert host.key > host.pem

Linux kernel version

Linux kernel version
--------------------------------
sris@sris:~$ uname -a
Linux sris 2.6.15-23-386 #1 PREEMPT Tue May 23 13:49:40 UTC 2006 i686
GNU/Linux


Linux flavor and version
-------------------------------------
sris@sris:~$ cat /etc/issue.net
Ubuntu 6.06 LTS