DevOps

Tuesday, 5 August 2014

Scripting Lab Exercise-2

Lab Exercise-2
1.    Create a data file called employee in the format given below:
a. EmpCode    Character
b. EmpName   Character
c. Grade           Character
d. Years of experience    Numeric
e. Basic Pay     Numeric
$vi employee
A001           ARJUN       E1      01      12000.00
A006           Anand         E1      01      12450.00
A010           Rajesh         E2      03      14500.00
A002           Mohan         E2      02      13000.00
A005           John             E2      01      14500.00
A009           Denial SmithE2      04      17500.00
A004           Williams      E1      01      12000.00
2.)  Sort the file on EmpCode.
$cut –f1 employee | sort
1.    Sort the file on EmpName.
$cut –f2 employee | sort
1.    Sort the file on
(i) Decreasing order of basic pay
(ii) Increasing order of years of experience.
(i) $cut –f5 employee | sort –r
(ii) $cut –f4 employee | sort
1.    Display the number of employees whose details are included in the file.
wc –l
1.    Display all records with ‘smith’ a part of employee name.
cut –f2 –d “ ” employee | grep ‘^[smith]’ | wc –l
1.    Display all records with EmpName starting with ‘B’.
$cut –f2 employee | grep ‘^[B]’ | wc –l
1.    Display the records on Employees whose grade is E2 and have work experience of 2 to 5 years.
$cut –f3 employee | grep ‘[*2] | cut –f4 employee | grep ‘[2-5]’
1.    Store in ‘file 1’ the names of all employees whose basic pay is between 10000 and 15000.
$cut –f2,5 employee | grep ‘[10000-15000]’ > rec
10. Display records of all employees who are not in grade E2.

$cut –f3 employee | grep ‘[*1]’

Scripting Lab Exercise-1

Lab Exercise-1
1.    WAP that accepts user name and reports if user logged in.
echo “Press or enter the user name”
read a
who >userlist
if grep $a userlist
then
echo “user logged on”
else
echo “user not logged on”
fi

2.    WAP that takes a filename as input and checks if it is executable, if not make it executable.
echo “Enter your file name”
read a
if [ ! –e $a ]
then
echo “file not exist”
elif [ ! –x $a ]
then
echo “file is not executable”
else
echo “we made it executable”
chmod 777 $a
fi

3.  WAP to take string as command line argument and reverse it.
echo “ Enter the string you want to reverse”
read string
len=`echo –n $string |wc –c`
echo “No. of characteristics : $len”
while test $len –gt 0
do
rev =$rev `echo $string | cut –c $len`
len=`expr $len – 1`
done
echo “The reverse string is : $rev”

4. WAP which displays the following menu and executes the option selected by user:
1. ls
2. pwd
3. ls –l
4. ps -fe
printf “\n\t 1. ls \n\t 2. pwd \n\t 3. ls -l \n\t 4.ps -fe\n\t “
echo “Enter your choice”
read a
case $a in
1) ls ;;
2)pwd ;;
3)ls -l;;
4)ps -fe;;
*)echo “Enter correct value”
esac

5. WAP to print 10 9 8 7 6 5 4 3 2 1 .
for i in 10 9 8 7 6 5 4 3 2 1
do
echo “$i”
done

6. WAP that prompts user for a starting value & counts down from there.
echo “Enter any value for countdown”
read a
while test $a -gt 0
do
echo $a
a=`expr $a – 1`
done
7. WAP that accepts initial value as a command line argument for ex.         If user writes contdown2 12 it should display the value from 12 to 1.
a=$1
while test $a -gt 0
do
echo $a
a=`expr $a – 1`
done

8. WAP that replaces all “*.txt” file names with “*.txt.old” in the current.
for i in *.txt
do
mv “ $i ” “ $i”.old

done