Monday, May 20, 2013

Vmware installation on operating system with KVM enabled

Search for modules loaded in memory  with string as kvm
lsmod |grep kvm

Remove those modules from kernel using the following command
modprobe -r kvm_intel
modprobe -r kvm

Install the rpm package which you have downloaded from www.vmware.com as per the operating system requirements.
rpm -i VMware-Player-2.5.5-328052.x86_64.rpm

Install the kernel-devel package from the configured repository in your system
yum -y install kernel-devel


Open up the VMware player, you will get a message that several modules must be compiled and loaded into the running kernel.Click on install.

You will get the same message again .This time , you click on cancel.
A window will open to open the Virtual Machine.

Friday, May 3, 2013

Apache in a Nut Shell

httpd -l lists the static libraries

You may have to edit configure script to resolve an error while installing apache.

I have been getting an error because I am trying to install mod_ssl
I am  running configure script and getting  an error that shows the line number .
You must try to understand the error messages  and see what is wrong.

Before installing apache make sure you have correct value of path variable. Installation will report error if something is wrong.
Edit your values ,properly.
Path variable needs to have proper kernel bin paths especially C compiler path.
What are you using CC or Gcc ?



If you are trying to reinstall apache then don't forget to clean the previous apache install using the  make clean command .

sudo ./configure --prefix=/apps/apache_xyz --enable-mods-shared='cern-meta deflate disk-cache headers info mem-cache mime-magic isapi proxy rewrite speling unique-id usertrack vhost-alias' --enable-modules=mod-ssl --with-ssl=/usr/local/bin/openssl
sudo make clean
sudo make install

sudo ./configure --prefix=/apps/apache_xyz --enable-cern-meta --enable-cache --enable-disk-cache --enable-mem-cache --enable-cern-meta --enable-deflate --enable-expires --enable-headers --enable-info --enable-logio --enable-mime-magic --enable-rewrite --enable-so --enable-speling --enable-ssl --enable-unique-id --enable-usertrack --enable-vhost-alias --with-ssl=/usr/local
sudo make clean
sudo make install

What is the difference in the above two commands?
First command is trying to install  shared libraries  ( dynamic libraries) 
There will be lines like LoadModule in the httpd.conf file for first installation.
Second command is trying to install libraries via static compiling .
You will not see  LoadModule sentences in the httpd.conf file for second installation
You can use the command  httpd -l for the second installation to list all statically compiled modules

There is also one more difference
first command is installing proxy and isapi modules
but the second command is not trying to install proxy and isapi modules.

Its better to install apache once again rather than adding a new module if you have a missing module.

You can't just copy and paste apache binaries ,they are dependent on your directory structure .


The two imporant files that store the configuration of apache are
httpd.conf  and ssl.conf  files.


How to get rid of passphrase while starting apache?

What do you get when you try to access a URL with http but at port 443?


E.g http://url:443




UNIX commands

To list disk usage
du -sg
du -sk
du -ksd in solaris to find the size of directory.

List all the directory usages in ascending order inside a particular directory in Solaris
du -sk *|sort -n

To get a formatted output on SunOS Solaris
df -F ufs -k
df -F ufs -k awk '{print $1}'
df -F ufs -k awk '{print $2}'
df -F ufs -k awk '{print $3}'
df -F ufs -k awk '{print $4}'
df -F ufs -k awk '{print $5}'
df -F ufs -k awk '{print $6}'

Print lines not containg #
crontab -l awk '!/#/'

Sum the fourth column
ls -lrt *2007*|awk '{ sum+=$5 }END{ print sum }'

Print the lines inside a tag e.g VirtualHost
awk '//' httpsd.conf

Using unix basic calculator
bc
scale=2
3/4
.75
^D to exit

Script to decrease the numeric contents of a file
var=`cat sample.txt`;
echo $var-1|bc > sample.txt

To list all processes that are using a file  which has been deleted from a given file system(e.g. /usr) in AIX
fuser -d /usr

Below command to add two files in parallel line by line -w 200 adjusts the default length of each line to 200
sdiff -w 200 1.txt 2.txt > 3.txt

To find all directories
find . -type d

find directories owned by a user
find - -type d -user username

Creating directories, recursively
mkdir -p /1/2/3

To list all the commands that are given permission to u by root
sudo -l

Changing the comment of a user
sudo usermod -c "username,#CUST#,ABC,Systems Administrator,F" username
Getting the error "UX: usermod: ERROR: username is in use. Cannot change it."
Then you can manually edit the /etc/passwd if you have permissions either using sudo or root for changing comments.

How to read mails for a user in UNIX ?
mailx
type ? for help
type d * at command prompt to clear all the mails .
This is useful in order to clean up /var (will perform clean up of /var/mail)

Recursive grep
find . -type f -exec grep HOST {} \;

Delete files with whose name begins with -
rm ./-badfile

find files accessed in last one day
find . -atime -1
find files not accessed in last one day
find . -atime +1

Display all the process that are currently using that file.
fuser filename

To know the architecture type on solaris
isainfo -kv
E.g.isainfo -kv
64-bit sparcv9 kernel modules

To know the default permissions of current directory
ls -lad
ls -ld

Display the system configuration like RAM etc.
prtconf on Sun Solaris
lsconf on AIX

Perfomance monitoring commands
vmstat
iostat
top on solaris and linux
topas on AIX
sar
netstat

To display the operation system name and version
uname
uname -a

What is /dev ?
The /dev directory contains the special device files for all the devices

pwck , grpck  are used for checking discrepancies in group and password files of solaris box.
The errors may not be that significant and they can be ignored even.

What are the files associated with name resolution on UNIX like systems ?
/etc/hosts
/etc/nsswitch.conf
/etc/resolv.conf

Where are Solaris System logs located ?
/var/adm/messages or you can run  dmesg command to view the logs.
/etc/syslog.conf has the System logs configuration.
/var/crash/  .Its not a readable file and you need Solaris crash analysis tool
 /var/log/syslog

Shell scripts

1)Arithmetic comparison and arithmetic addition
 s=1;
while( [ $s -lt 100 ] )
do
echo $s;
s=$[$s + 2];
done

2)Read  input
read input
echo "Welcome $input"

3)Display the first positional parameter
echo "Welcome $1"

4)Display the natural number from 1 to 50
for i in {1..50}do
echo $i;
done

5)Usage of if and arithmetic comparison operatorsread a;
read b;
if([ $a -lt $b ]) then
echo "X is less than Y";
fi
if([ $a -gt $b ]) then
echo "X is greater than Y";
fi
if([ $a -eq $b ]) then
echo "X is equal to Y";
fi


6)Usage of string comparison operators.
read input;
if ([ "$input" == 'y' ] || [ "$input" == 'Y'  ]) then
echo "YES";
fi
if ([ "$input" == 'n' ] || [ "$input" == 'N' ]) then
echo "NO";
fi


7) Usage of logic operators and if condition.

read a;
read b;
read c;
if ( [ $a -eq $b ] && [ $b -eq $c ] ) then
echo "EQUILATERAL"
elif ( [ $a -eq $b ] || [ $b -eq $c ] || [ $c -eq $a ] ) then
echo "ISOSCELES"
else
echo "SCALENE"
fi


8)Below script shows the usage of bc to perform arithmetic operations. Scale = 4 directs bc to compute upto 4 decimal places  and printf rounds the result to 3 decimal places.  a is an arithmetic expression sent as an input to the script E.g. 2+2-5*6/4*7

read a;
b=`echo "scale=4;$a"|bc`
printf %.3f $b;


9)Below script takes n integers which is first input and then all the integers one by one .The task is to calculate  the average . The script combines printf to round the result to 3 places and bc to calculate the average upto 4 decimal places . While loop is used to calculate  the sum of numbers by iterating exactly n times.

read n;
i=0;
s=0;
while ([ $i -lt $n ])
do
read input;
s=$[$s+$input];
i=$[$i+1];
done
average=`echo "scale=4;$s/$n"|bc`;
printf %.3f $average;

10) Display the 3rd character of each line given as input .

cut -c 3
E.g. echo "Hello World"|cut -c 3 displays l as output .
cut -c 2,7 will display the 2nd and 7th  character of the lines given as input.
cut -c 2-7  will display from 2nd to 7th  character of the lines given as input.
cut -c 13-  will display from 13th character to the end of the line.

11) Display first 3 fields of input delimited by tab. TAB is the default delimiter for cut.
f specifies the fields . Here, first to third field are displayed.
 cut  -f 1-3
cut -d " " -f 4 displays fourth field delimited by single space. cut -d " " -f 1-3 displays first to third  field delimited by single space.
cut -f 2-  displays second to last  field delimited by tab.

12)Below script displays first 20 lines of a file.

i=1;
while ( [ $i -lt 21 ])
do
read input;
echo $input;
i=$[$i+1];
done


head -c 12 . Displays first 12 characters of a file.
head -n 20 . Displays first 20 lines of file
head -n 20|tail -n +12 . Displays 12th to 20th line of file
tail -n -20 . Displays last 20 lines of file.
tail -c 20 . Displays last 20 characters of a file.


13)If you want to write  the name of all the Queue Manager  to a single file to create a stop/start script for WebSphere MQ
dspmq|cut -d'(' -f1|cut -d')' -f1 > strmq.sh

14)
Removing control M characters from several files at a time in UNIX platforms
find . -name *.sh -exec perl -pi -e 's/^M//g' {} \;

Make sure to type control M character , do not copy and paste control M character .
You have to type control M by pressing ctrl v and ctrl m one after another

then check again for control M character with the below command
 find . -name *.sh -exec grep -l "^M" {} \;


15)
If you want to remove control M character from a single file
perl -pi -e 's/^M//g'  FILE NAME


16)Below script replaces ( to [ and ) to ]. Take a note that we have only used -p not -pi . When you use i , command expects you to provide an input file name .

 perl -p -e 's/\(/\[/g'  |perl -p -e 's/\)/\]/g'


17)Replace 2 or more spaces with one .

perl -p -e 's/ +/ /g'

18) sort  . Sorts on first column
sort -r. Sorts on first column in reverse order
sort -n. Sorts on  numeric column. Only one numeric column is present.
sort -n -r . Sorts on numeric column in reverse order. Only one numeric column is present


19)Below script converts the input
A 25 27 50
B 35 37 75
C 75 78 80
D 99 88 76
 
to output
 
A 25 27 50 : FAIL
B 35 37 75 : FAIL
C 75 78 80 : B
D 99 88 76 : A 
 
awk 'BEGIN{} {sum=$2+$3+$4;mean=sum/3;if( mean >= 80 ) print 
$1,$2,$3,$4,":","A"; else if( mean >= 60 )print $1,$2,$3,$4,":","B"; 
else if( mean >= 50 ) print $1,$2,$3,$4,":","C"; else print 
$1,$2,$3,$4,":","FAIL";} END{}'  

20)
Below script converts the input 
A 25 27 50
B 35 37 75
C 75 78 80
D 99 88 76 
 
to 
 
A 25 27 50;B 35 37 75
C 75 78 80;D 99 88 76 
 
awk '{if(NR%2==0) printf $0"\n"; else printf $0";";}'
 
Note that when you change the printf to print the output changes to 
A 25 27 50;
B 35 37 75

C 75 78 80;
D 99 88 76
 
 
8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR
 
https://www.thegeekstuff.com/2010/01/8-powerful-awk-built-in-variables-fs-ofs-rs-ors-nr-nf-filename-fnr/?ref=binfind.com/web
 
 
21) 
grep  "[t,T]he " 
searches for the line containing string "the"

grep -v "[t,T]hat " displays lines which do not contain that .

grep -e "[t,T]he " -e "[t,T]hat " -e "[t,T]hen " -e "[t,T]hose "  searches for the words the, that ,then , those

 

22) Copy a file specified on the input prompt from one location to another .If the file already exists in the other location ,then rename the file using date as suffix and then copy.
"$ cat testscript.sh
echo "Enter the name of file"
read file
echo $file
Date=`date|cut -f1 -d ' ' `
if(test -e $file)
then
mv $file $file$Date
cp TEST1/$file ./
echo $?
else
cp TEST1/$file ./
fi

$ echo $?
0

if [ $? -eq 0 ]
then
echo "Success"
fi


23)Script to check whether list of files written in a FILE 'TEMP1.txt' exist in directory inside which the script is run

for file in `cat filelist.txt`
do
if(test -e $file)
then
c=0
else
echo $file >> ListOfFiles.txt
fi
done

24)Find files containing a string and then replace string with new string in those files

find . -type f -exec cmd.sh "jdbc\/SomeDB" {} \;
OR
find . -type f -exec ./cmd.sh "jdbc\/SomeDB" {} \;

##contents of cmd.sh
grep $1 $2
if [ $? -eq 0 ]
then
echo $2 >> filenames.txt
fi
##Below script to replace
for file in `cat filenames.txt`
do
sed 's/old_string/new_string/g' $file > $file.new
mv $file.new $file
done

25)Merge files line by line in UNIX
 paste file1 file2 > file3

Generic Numeric Sorting on second column seperated by tab in descending order
sort -t$'\t' -k2 -g -r
Generic Numeric Sorting on second column seperated by | in descending order
sort -t'|' -k2 -g -r
Generic Numeric Sorting on second column seperated by | in ascending order
sort -t'|' -k2 -g

Remove duplicates in standard input
Uniq

Counts and displays number of consecutive duplicates
uniq -c|xargs -l

Counts and displays number of consecutive duplicates and ignore cases
uniq -ic|xargs -l

Convert newline to tab from a standard input
awk 'BEGIN{ORS="\t";}{print;} END{}'

Thursday, May 2, 2013

C for Conflicts

For some people ,it meant nothing, for some it meant something and for some it meant everything.



He was the one ,for whom it meant everything and when he came to realize that for others it meant nothing,he felt like dead.His head burnt like fire and the conflicts started in his little mind.


Conflicts about what happened to him was wrong or what he did was wrong or the world is wrong or what others say is wrong.And here started the world of skepticism in him.Arguing about the things..arguing about everything..arguing against even about science ..arguing against even about the fundamentals of society.