Wednesday, September 10, 2008

Compress and uncompress the files in Linux with tar

To compress folder myfolder to myfolder.tar.gz

tar czfv myfolder.tar.gz myfolder/
czfv = "compress gzip file archive with verbose output"

If you want bzip files, use ‘j’ instead of ‘z’.

tar cjfv myfolder.tar.gz myfolder
cjfv = "compress bzip file archive with verbose output"


Uncompress myfolder.tar.gz to folder myfolder/

tar -xzf Test.tar.gz
xzf = ‘extract gzipped file archive’

Again, if you want bzip files, use ‘j’ instead of ‘z’.

tar -xzf Test.tar.gz
xjf = ‘extract bzipped file archive’

Tuesday, August 19, 2008

Setting the inital file permissions using umask

umask command is used to set the default permission modes for newly created files in the current shell and its child processes.

umasks are calculated as the AND of the unary complement of the argument (NOT) and the full access mode.

The full access mode is 666 in the case of files, and 777 in the case of directories

A common umask value is 022 (masking out the write permission for the group and others), which ensures that new files are only writable for the owner (i.e. the user who created them). Another common value is 002, which leaves the write permission for the file's group enabled. This can be used for files in shared workspaces, where several users work with the same files.

Example usage of setting umask

Assuming the umask has the value 163, any new file will be created with the permissions 604 and any new directory will have permissions 614 because:

666 AND NOT(174) = 604
666=110 110 110
163 = 001 110 011
NOT(001 110 011) = (110 001 100)
(110 110 110) AND (110 001 100) = (110 000 100)
777 NOT (163) = 604
while

777 AND NOT(163) = 614

777 = 111 111 111
163 = 001 110 011
NOT(001 110 011) = (110 001 100)
(111 111 111) AND (110 001 100) = (110 001 100)
777 NOT (163) = 614

Monday, August 11, 2008

Attaching serial console on a Linux box

Step # 1: Setup Serial redirection

By default, grub output does not appear on the remote console; it only appears on the local terminal. However, you can configure your grub.conf file to redirect all grub output to the remote console. Redirection will display the grub output on the remote console, but not on the local terminal. To redirect grub output, make the following changes to your /etc/grub.conf file:


# vi /boot/grub/grub.conf
Append the following lines in the file

serial --unit=1 --speed=19200 --word=8 --parity=no --stop=1
terminal --timeout=8 console serial

* The first line tells GRUB to use the first serial port at a baud rate of 19200
* The second line gives the user 9 seconds to decide where GRUB should output it's information.
* Please adjust port number and speed as per your setup.

Next make sure splashimage options is disabled as graphics can't be displayed across the serial port. Remove splashimage line or just comment it out by prefixing # symbol:
#splashimage=(hd0,0)/grub/splash.xpm.gz

Also please comment out the hiddenmenu option ( We had some issues at times when tried using this, so to be on safer side,disable it )


Step # 2: Enabling serial output from the Linux kernel


Find the kernel line (grub config file) which corresponds to your currently running kernel. Add the following at the end of that line - console=tty0 console=ttyS0,9600n8:

title Red Hat Enterprise Linux ES (2.6.9-42.0.10.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-42.0.10.ELsmp ro root=LABEL=/ console=tty0 console=ttyS1,19200n8
initrd /initrd-2.6.9-42.0.10.ELsmp.img


On Red Hat EL nodes, please make the following changes

* Set SAFE=YES in /etc/sysconfig/kudzu

Remote installation of OpenSuse-11 on an IBM PPC

1. Setup the DHCP/BOOTP/PXE/TFTP server to boot from network
3. Boot from network
4. The yaboot prompt will appear. Please enter
install vnc=1 ssh=1
to start the installation on vnc and to enable ssh connections.
5. You'll be asked to enter the vnc and ssh password. Please enter a password of your choice here.
Enter your VNC password>
Enter your temporary SSH password>
6. You'll be asked to choose the network interface you want to use.
Choose the network device.
1) eth1 : Broadcom NetXtreme BCM5704S Gigabit Ethern
2) eth0 : Broadcom NetXtreme BCM5704S Gigabit Ethern
Automatic configuration via DHCP?
1) Yes
2) No

7 Opensuse now starts the installer, Connect to the VNC server with a viewer of your choice
vncviewer :1

Saturday, July 19, 2008

Special character ; at bashprompt

; is used as a command separator and to terminate a case statement at bash

#!/bin/bash

# This script is to explain the usage of the ; as a special character in bash.
# Sijo George
#--------------------------START-------------------------------
echo "Hello world,"; echo "How are you?"; # Execute two commands in a line using a ; delimiter
case $1 in
[a-z] ) echo " The input is an alphabet " ;; # Terminator in the case option
[0-9] ) echo " The input is a number" ;;
* ) echo " The input is neither an alpabet or a number ";;
esac

Thursday, July 17, 2008

Usage of Special character '#' at bash

Read through the script below. This better explains the usage

#!/bin/bash
# This script is to explain the special char #
# Sijo George sijo.george@gmail.com
#------------------START------------------------#
#This is a comment
echo "This is #not a comment"
echo 'This also # is not a comment'
echo But ...This is a #comment
echo However This \# is not a comment
echo "Parameter sub is not a comment"
echo ${PATH}
echo ${PATH#*:};# Cuts of the shortest string of pattern after the # from the front
echo ${PATH##*:};# Cuts of the longest string of pattern after the # from the front
echo "Base conversion is not a comment "
echo $((2#1010)) # Convers binary 1010 to decimal
echo $((16#ABCD)) # Converts hex ABCD to decimal
string="this is a string"
echo ${#string} # Gives the number of characters in the string
array=(1 test a 10)
echo ${#array} # Gives the length of first element of the array
echo ${#array[*]} # Gives the number of elements in the array
echo ${#array[@]} # Gives the number of elements in the array
echo ${#} # Gives the number of command line parameters.
echo ${#*} #Gives the number of command line parameters.
echo ${#@} #Gives the number of command line parameters.

Thursday, February 21, 2008

Keyboard shortcuts at bash prompt

Alt + < - Move to the first line in the history
Alt + > - Move to the last line in the history
Alt + ? - Show current completion list
Alt + * - Insert all possible completions
Alt + / - Attempt to complete filename
Alt + . - Yank last argument to previous command
Alt + b - Move backward
Alt + c - Capitalize the word
Alt + d - Delete word
Alt + f - Move forward
Alt + l - Make word lowercase
Alt + n - Search the history forwards non-incremental
Alt + p - Search the history backwards non-incremental
Alt + r - Recall command
Alt + t - Move words around
Alt + u - Make word uppercase
Alt + backspace - Delete backward from cursor
Ctrl + a - Jump to the start of the line
Ctrl + b - Move back a char
Ctrl + c - Terminate the command
Ctrl + d - Delete from under the cursor
Ctrl + e - Jump to the end of the line
Ctrl + f - Move forward a char
Ctrl + k - Delete to EOL
Ctrl + l - Clear the screen
Ctrl + r - Search the history backwards
Ctrl + R - Search the history backwards with multi occurrence
Ctrl + u - Delete backward from cursor
Ctrl + xx - Move between EOL and current cursor position
Ctrl + x @ - Show possible hostname completions
Ctrl + z - Suspend/ Stop the command

Fun with bash - Addition at bash prompt

Addition at bash prompt can be done in many ways. I have managed to collate some of them in the script below. The script below counts from 1 to 14 in 14 different ways. Its fun isn't it. It shows how powerful and feature-rich this simple scripting language is.

#!/bin/bash
n=1;
echo -n "$n, "
let "n = $n + 1"
echo -n "$n, "
: $((n = $n + 1))
echo -n "$n, "
(( n = n + 1 ))
echo -n "$n, "
n=$(($n + 1))
echo -n "$n, "
: $[ n = $n + 1 ]
echo -n "$n, "
n=$[ $n + 1 ]
echo -n "$n, "
let "n++"
echo -n "$n, "
(( n++ ))
echo -n "$n, "
: $(( n++ ))
echo -n "$n, "
: $[ n++ ]
echo -n "$n, "
n=`echo "$n + 1" | bc`
echo -n "$n, "
n=`echo "$n + 1" | bc -l`
echo -n "$n, "
n=`expr $n + 1`
echo "$n"

Wednesday, February 20, 2008

Adaruvan Vayya

I love this poem written by ONV recited by Madhusoodanan Nair, specially the last three lines


Irulin mahaanidrayil ninnunarthi nee niramulla jeevitha peeli thannu
ente chirakinaakashavum nee thannu ninn aathma shikirathil oru koodu thannu

Oru kunju poovilum thalirkaatilum ninne neeyayi manakunnathengu vere...
jeevanozhukumbol oruthulli ozhiyathe neethanne nirayunna puzhayengu vere...
kanavinte ithalaayi ninne padarthi nee viriyichoraakashamengu vere...

Oru kochu raapadi karayumbozhum nerthoraruvi than thaarattu thalarumbozhum
kaniviloru kallu kanimadhuramavumbozhum kaalamidarumpozhum ninte -
hridayathil njanente hridayam koruthirikunnu...
ninill abhayam thiranju pokunnu...

Adaruvan vayya..... nin hridayathil ninnenikethu swargam vilichaalum
uruki nin aathmaavin aazhangalil veenu poliyumbozhaanente swargam
ninnil adiyunnathee nitya sathyam

See the video of the song from the film Daivathinte Vikrithikal

The opening ceremony

Well.. I'm here ..
Lemme open this with a note to my sweetheart..

You're my best friend in the good times
and my rock in times of sorrow.
You're the reason for sweet yesterdays
and my promise for tomorrow.

My love, The sea nor land, nor death itself can extinguish or lessen toward you, most endearedly visits you with eternal embraces, and will abide with you for ever: and may the God of my life watch over you, and bless you, and do you good in this world, and for ever.