URDINESH: July 2015

Software Programming, Tutorials, Interview Preparations,Stock Market,BSE/NSE, General informations

Sunday, July 26, 2015

Shell Program To Extract the Message from Shared Memory


#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
main()
{
int shmid,i;
char *pa,a[1000];
shmid=shmget((key_t)1300,1024,0600|IPC_CREAT);
if(shmid==-1)
{printf("shmget failed");
return;
}
pa=(char*)shmat(shmid,0,0);
if(pa==(void *)-1)
{
printf("shmat failed");
return;
}
printf("The text recived is: \n");
puts(pa);
}



Output:


[user@localhost ~]$ cc emgsh.c
[user@localhost ~]$ ./a.out
The text recived is:
Message stored in shared memory
shared memory programs

[user@localhost ~]$ 

Shell Program for Read & Print the text using shared memory



#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
main()
{
int shmid,i;
char *pa,a[1000];
shmid=shmget((key_t)1300,1024,0600|IPC_CREAT);
if(shmid==-1)
{printf("shmget failed");
return;
}
pa=(char*)shmat(shmid,0,0);
if(pa==(void *)-1)
{
printf("shmat failed");
return;
}
printf("Enter text&press$to terminate\n");
for(i=0;(a[i]=getchar())!='$';i++);
a[i]='\0';
strcpy(pa,a);
printf("The given text is placed into shared memory\n");
}


OutPut




[user@localhost ~]$ cc mgsh.c
[user@localhost ~]$ ./a.out
Enter text&press$to terminate
Message stored in shared memory
shared memory programs$
The given text is placed into shared memory

[user@localhost ~]$ 

Wednesday, July 22, 2015

SHELL SCRIPT TO COPY ONE FILE TO ANOTHER FILE

COPY ONE FILE TO ANOTHER FILE:

echo "copying one file to another"
if [ $# -eq 4 ]
then
   cp $3 $1
   cp $4 $2
 fi
























OUTPUT:

[@localhost ~]$ cat f3
hai this is rajasekar
[@localhost ~]$ cat f4
i did my pg in nmc
[@localhost ~]$ sh copy.sh f1 f2 f3 f4
copying one file to another
[@localhost ~]$ cat f1
hai this is rajasekar
[@localhost ~]$ cat f2
i did my pg in nmc

SHELL SCRIPT TO REMOVE THE LINES IN A GIVEN PATTERN

REMOVE THE LINES IN A GIVEN PATTERN:


echo "Enter file name"
read file
echo "Enter pattern"
read pat
grep -v $pat $file







OUTPUT:

[@localhost ~]$ sh pattern.sh
Enter file name
raja
Enter pattern
did
HAI I AM RAJASEKAR
I DID MY STUDIES IN NMC
I COMPLEATED MY PG DEGREE IN MBA AND MCA
I AM ALWAYS BE A OVER-CONFIDENT PERSON
THEN ONLY LEADS TO VERY SUCCESSFULL MANNER

[@localhost ~]$ sh pattern.sh
Enter file name
raja
Enter pattern
COMPLEATED
HAI I AM RAJASEKAR
I DID MY STUDIES IN NMC
I AM ALWAYS BE A OVER-CONFIDENT PERSON
THEN ONLY LEADS TO VERY SUCCESSFULL MANNER

[@localhost ~]$ sh pattern.sh
Enter file name
raja
Enter pattern
I
THEN ONLY LEADS TO VERY SUCCESSFULL MANNER

Tuesday, July 21, 2015

SHELL SCRIPT TO GET NO OF SUBDIRECTORY IN CURRENT DIRECTORY

ALL SUBDIRECTORY IN CURRENT DIRECTORY:

echo "to display all sub directory"
for i in *
do
if [ -d $i ]
then
echo $i "is an directory"
fi
done





OUTPUT:

[@localhost ~]$ sh subdirt.sh
to display all sub directory
123 is an directory

324@86 is an directory

SHELL SCRIPT TO PAYBILL PREPARATION

PAYBILL PREPARATION:


 echo -e "\tPAYBILL CALCULATION"
echo -e "\t~~~~~~~~~~~~~~~~~~~~"
echo -e "\tenter the n value"
read n
echo -e "\tenter name id salary"
for((i=1;i<=n;i++))
do
`read name id salary
echo -e "\tbefore calculation"
echo -e "\t***********************"
echo -e "\tname\t:$name\n\tid\t:$id\n\tsalary\t:$salary"
echo -e "\t***********************"
echo -e "\t calculation part"
if [ $salary -lt 10000 ]
then
lic=`expr $salary*0.05|bc`
echo -e "\n\tlic:\t"$lic
pf=`expr $salary*0.03|bc`
echo -e "\n\tpf:\t"$pf
ded=`expr $lic+$pf|bc`
echo -e "\n\tded:\t"$ded
hra=`expr $salary*0.03|bc`
echo -e "\n\thra:\t"$hra
da=`expr $salary*0.08|bc`
echo -e "\n\tda:\t"$da
add=`expr $hra+$da|bc`
echo -e "\n\tadd:\t"$add
gpay=`expr $salary-$ded|bc`
echo -e "\n\tgpay:\t"$gpay
npay=`expr $gpay+$add|bc`
echo -e "\n\tnpay:\t"$npay
echo -e "\n\tafter calculation"
echo -e "\n\t*********************"
echo -e "\n\tname\t:$name\n\tid\t:$id\n\tnetpay\t:$npay"
echo -e "\n\t***********************"
else
lic=`expr $salary*0.05|bc`
echo -e "\n\tlic:\t"$lic
pf=`expr $salary*0.03|bc`
echo -e "\n\tpf:\t"$pf
ded=`expr $lic+$pf|bc`
echo -e "\n\tded:\t"$ded
hra=`expr $salary*0.03|bc`
echo -e "\n\thra:\t"$hra
da=`expr $salary*0.08|bc`
echo -e "\n\tda:\t"$da
add=`expr $hra+$da|bc`
echo -e "\n\tadd:\t"$add
gpay=`expr $salary-$ded|bc`
echo -e "\n\tgpay:\t"$gpay
npay=`expr $gpay+$add|bc`
echo -e "\n\tnpay:\t"$npay
echo -e "\n\tafter calculation"
echo -e "\n\t*********************"
echo -e "\n\tname\t:$name\n\tid\t:$id\n\tnetpay\t:$npay"
echo -e "\n\t***********************"
fi
done































OUTPUT:

[@localhost ~]$ sh paybill.sh
        PAYBILL CALCULATION
        ~~~~~~~~~~~~~~~~~~~~
        enter the n value
2- INSERT --
        enter name id salary
rajasekar 324 100000
        before calculation
        ***********************
        name    :rajasekar
        id      :324
        salary  :100000
        ***********************
         calculation part

        lic:    5000.00

        pf:     3000.00

        ded:    8000.00

        hra:    3000.00

        da:     8000.00

        add:    11000.00

        gpay:   92000.00

        npay:   103000.00

        after calculation

        *********************

        name    :rajasekar
        id      :324
        netpay  :103000.00


        ***********************

SHELL SCRIPT TO COMPARE TWO FILE

COMPARE TWO FILE:
cmp $1 $2
if [ $? -eq 0 ]
then
echo "Both files are EQUAL"
else
echo "Both files are NOTEQUAL"
fi























OUTPUT:

[@localhost ~]$ ls
acceptlogin.sh  current.sh     file1.sh     mark.sh  pol        totaldir.sh
add.sh          dcurrent.sh    file1.txt    new1.c   pol.sh     tri.sh
a.out           eletricity.sh  file2.txt    new1.sh  raj        userlog
big.sh          fact           fileper      new.c    raja.c     userlog.sh
big.shwq        fact.sh        fileper.sh   op.sh    series.sh  x.txt
com.sh          fib.sh         firstlet.sh  per.sh   subdir.sh  y.txt


[@localhost ~]$ sh com.sh fib.sh fact.sh
fib.sh fact.sh differ: byte 1, line 1
Both files are NOTEQUAL

[@localhost ~]$

SHELL SCRIPT FOR FIBONACCI SERIES

FIBNOCIS SERIES:

echo "Enter choice="
read n
fib1=0
fib2=1
echo "The series are=$fib1 $fib2"
for ((i=0; $i<$n; i=`expr $i + 1|bc`))
do
fib3=`expr $fib1 + $fib2 |bc`
fib1=$fib2
fib2=$fib3
echo "$fib3"
done
















OUTPUT:
 [@localhost ~]$ sh fib.sh
Enter choice=
10
The series are=0 1
1
2
3
5
8
13
21
34
55
89

[@localhost ~]$

SHELL SCRIPT TO FETCH FILES WHICH STARTS WITH ‘A’ IN THE CURRENT DIRECTORY

FILES WHICH STARTS WITH ‘A’ IN THE CURRENT DIRECTORY:



for i in *
do
  x=$(echo $i|cut -b 1)
  if [ $x = "a" ]
  then
    echo $i
  else
    continue
  fi
  done




















OUTPUT:

[@localhost ~]$ sh firstlet.sh a
acceptlogin.sh
add.sh

a.out

SHELL SCRIPT FOR ELECTRICITY BILL PREPARATION

ELECTRICITY BILL PREPARATION:


echo "enter the pmr cmr"
read  pmr cmr
echo "PreviousMonthReading: $pmr"
echo  "CurrentMonthReading: $cmr"
unit=`echo $cmr - $pmr |bc`
echo " unit  :  $unit"
if [ $unit -ge 200 ]
then
amt=`echo $unit \* 2.00 | bc`
else
 if [ $unit -lt 200 -a $unit -ge 100 ]
then
amt=`echo $unit \* 1.50 | bc`
 else
   amt=`echo $unit \* .50 | bc`
fi
fi
echo " Amount  : $amt"















OUTPUT:

[@localhost ~]$ sh eletricity.sh
enter the pvr cvr
700 950
PreviousMonthReading: 700
CurrentMonthReading: 950
 unit  :  250
 Amount  : 500.00

[@localhost ~]$

Monday, July 20, 2015

SHELL SCRIPT TO ACCEPT USERNAME AS COMMAND LINE ARGUMENTS AND CHECK THE USER LOGIN IN OR NOT

ACCEPT USERNAME AS COMMAND LINE ARGUMENTS  AND CHECK    THE USER LOGIN IN OR NOT

 echo "To check the user login or not"
if [ $# -eq 1 ]
then
who > y.txt
c=`grep -n $1 y.txt | wc -l`
fi
if [ $c -gt 0 ]
then
echo "The user has login"
else
echo "The user has not login"
fi





















OUTPUT:
 [@localhost ~]$ sh acceptlogin.sh 2k7ca320
To check the user login or not
The user has login
[@localhost ~]$ sh acceptlogin.sh 2k7ca337
To check the user login or not
The user has not login

[@localhost ~]$

SHELL SCRIPT TO CHECK HOW MANY TIMES THE SPECIFIC USER HAS LOGIN

CHECK HOW MANY TIMES THE SPECIFIC USER HAS LOGIN:

echo "To count the user login"
read username
who > x.txt
c=`grep $username x.txt | wc -l`
echo "The user has logged $c times"

































OUTPUT:
 [@localhost ~]$ sh userlog.sh
To count the user login
27324
The user has logged 1 times

[@localhost ~]$ 

SHELL SCRIPT TO DISPLAY THE NO OF FILES IN THE CURRENT DIRECTORY

DISPLAY THE NO OF FILES IN THE CURRENT DIRECTORY:

echo "to count the file in the directory"
count=0
for i in *
do count=`expr $count + 1`
done
echo $count




























OUTPUT:

[@localhost ~]$ sh totaldir.sh
to count the file in the directory
26

[@localhost ~]$

KENDO GRID HEADER SORTING IS NOT WORKING IN IE11 FIXED

Hi All,

Many of us struck with sorting by clicking of header in Kendo UI
Grid ON IE 11 is not working. 


Here is the solution,



 In the Declararion of kendo Grid we have line linke Below,

.HtmlAttributes(new { style = "position: relative; z-index: 11000" })


Please remove the highlighted style(i.e. z-index: )
Example:

.HtmlAttributes(new { style = "position: relative;" })

Now Check your grid by running the code...

KENDO GRID ROW SELECTION ON IE11 FIXED

Hi All,

Many of us struck with displaying hyper link in Kendo UI
Grid ON IE 11. 


Most of the times the hyperlink is not clickable,

Here is the solution,



 In the Declararion of kendo Grid we have line linke Below,

.HtmlAttributes(new { style = "position: relative; z-index: 11000" })


Please remove the highlighted style(i.e. z-index: )
Example:

.HtmlAttributes(new { style = "position: relative;" })

Now Check your grid by running the code...

Sunday, July 19, 2015

SHELL SCRIPT PROGRAMS












  • SHARED MEMORY

SHELL SCRIPT TO CHECK IF THE FILE HAS ALL PERMISSION

CHECK IF THE FILE HAS ALL PERMISSION:
  
echo "checking file permission"
read fn
if [ -r $fn -a -w $fn -a -x $fn ]
then
echo "The file has all permission"
else
echo "The file has not all permission"
fi





















OUTPUT:
 
  [localhost ~]$ sh fileper.sh
checking file permission
pol.sh
The file has not all permission
[localhost ~]$ chmod 777 pol.sh
[localhost ~]$ sh fileper.sh
checking file permission
pol.sh
The file has all permission

[localhost ~]$

SHELL SCRIPT TO FIND POLYNDROME

Polyndrome Or Not:

count=`echo $1 | wc -c`
count=`echo $count - 1|bc`
echo "length of the given string is:"$count
while [ $count -gt 0 ]
do
rev1=`echo $1 | cut -b $count`
rev2=$rev2$rev1
count=`expr $count - 1`
done
if [ $rev2 = $1 ]
then
echo "string is palindrome"
else
echo "string is not palindrome"
fi

















OUTPUT:
 [localhost ~]$ sh pol.sh madam
Length of The Given String is:5
String is Palindrome
[localhost ~]$ sh pol.sh sir
Length of The Given String is:3
String is Not Palindrome
[localhost ~]$ sh pol.sh malayalam
Length of The Given String is:9
String is Palindrome
[localhost ~]$

SHELL SCRIPT TO FIND BIGGEST OF THREE NUMBERS

BIGGEST OF THREE NUMBERS:

if [ $# -eq 3 ]
then
echo "All the no.'s are entered"
if [ $1 -gt $2 -a $1 -gt $3 ]
then
echo "The First Number is Greater " $1
else
if [ $2 -gt $3 ]
then
echo "The 2nd Number is Greater " $2
else
echo "The 3rd Number is Greater " $3
fi
fi
else
echo "Enter three numbers Again"
fi



















OUTPUT:

[localhost ~]$ sh big.sh 24  89 -22
All the no.'s are entered
The 2nd Number is Greater  89
[localhost ~]$

SHELL SCRIPT TO PRINT N TRIANGLE

TRIANGLE:

echo "Triangle"
for((i=1;i<=5;i++))
do
for((j=1;j<=i;j++))
do
echo -n $i
done
echo -e "\n"
done

















OUTPUT:

Triangle
1

22

333

4444

55555

[2k7ca324@localhost ~]$


SHELL SCRIPT FOR OPERATORS

Operator

echo "Enter the Operator"
read a
echo "Name of Operator is: "
case $a in
+) echo "Addition"
   ;;
-) echo "Subtraction"
   ;;
\*) echo "Multiplication"
   ;;
/) echo "Division"
   ;;
*) echo "Not an Operator"
   ;;
esac


OUTPUT:

enter the operator
+
name of operator is:
addition
[2k7ca324@localhost ~]$ sh op.sh
enter the operator
-
name of operator is:
subtraction
[2k7ca324@localhost ~]$ sh op.sh
enter the operator
*
name of operator is:
multiplication
[2k7ca324@localhost ~]$ sh op.sh
enter the operator
/
name of operator is:
division
[2k7ca324@localhost ~]$ sh op.sh
enter the operator
%
name of operator is:

not an operator

SHELL SCRIPT TO PRINT STUDENT MARK LIST

STUDENT MARK LIST:

echo "Enter the no. of Students"
read n
for(( i=1;i<=n;i++ ))
do
 echo "Enter Name,Mark1 and Mark2"
 read name
 read mark1
 read mark2
 tot=`echo $mark1+$mark2|bc`
 if [ $mark1 -ge 40 -a $mark2 -ge 40 ]
 then
 res="Pass"
 else
 res="Fail"
 fi
avg=`echo $tot/2|bc`
echo "NAME"  $name
echo "MARK1" $mark1
echo "MARK2" $mark2
echo "TOTAL" $tot
echo "Average"  $avg
echo "Result" $res
done






















OUTPUT:
enter the no. of students
2
enter name,mark1 and mark2
geetharani
87
56
name geetharani
mark1 87
mark2 56
total 143
average 71
result pass
enter name,mark1 and mark2
ranjani
78
98
name ranjani
mark1 78
mark2 98
total 176
average 88
result pass

SHELL SCRIPT TO PRINT TRIANGLE

TRIANGLE:
clear
#geNerate the pyramid
echo "the series is"
for((i=5;i>=1;i--))
do
for((j=5;j>=i;j--))
do
echo -n $j " "
done
echo  -e
done


















OUTPUT:

the series is
5
5  4
5  4  3
5  4  3  2

5  4  3  2  1

SHELL SCRIPT TO FIND FACTORIAL

FACTORIAL
clear
#factorial of n numbers
echo "enter the number"
read num
fact=1
for((i=1;i<num+1;i++))
do
fact=`expr $fact \* $i`
done
echo "the factorial of $num is $fact"













OUTPUT:
enter the number
5
the factorial of 5 is 120

[2k7ca324@localhost ~]$

Followers