Part A: mcs 041
Question 1:
Write and demonstrate the UNIX commands for the following:
(a) Find the number of users currently logged in.
Answer
who
(b) Find the number of lines in a specified file.
Answer
wc – l filename
(c) Kill a background process.
Answer
kill processnumber
eg : kill 1000.
(d) Display the current environment variables.
Answer
set | less
(e) Change the file permissions to Read only for everyone on a data file created by you.
Answer
Chmod o+r file1
(f) Find the lines in a file that contains the string like b or ab or aab or aaab or aaaa…b
Answer
egrep -i “ab|aaaa|b|aaab” filename
(g) Transfer the names of all the files in a directory to a file.
Answer
cp -R /home/scripts /export/home/SIVA
(h) Display a file such that only 10 lines get displayed at one time.
Answer
Cat filename|head 10
(i) Create a file containing 10 lines, split it into two files containing 5 lines each.
Answer
split -l 5 file1.txt smallsplit.txt
(j) Display only those lines that are common in two different files.
Answer
$ comm -3 /path/to/file1/ /path/to/file2
Question 2:
(a) Create a text file containing name, ID and addresses of students. Write a shell program that displays only the name
and ID of the students.
Answer :
Create file
Vi student.txt
Name: siva
ID : 2120
Address:Tiruchendur
Name: Venkat
ID : 2121
Address: Chennai.
Name: Raja
ID : 2122
Address: Koimbatore.
Schell Program
egrep -i “name|id” student.txt
(b) Write a shell script that counts the number of occurrences of the word “IGNOU” in a file.
Answer :
#!/bin/bash
count=0
a=1
for i in $(cat check1.txt)
do
if [[ $i == $1 ]]; then
count='expr $count + $b'
fi
done
echo $count
(c) Write a shell script that displays the smaller of the two values given as arguments to it.
Answer :
compare2.sh
a=$1
b=$2
if [[ $a -le $b ]] ; then
echo “Smaller value is : $a.”
else
echo “Smaller value is : $b.”
fi
To Run Script
./compare2.sh 5 12
Smaller value is : 5
PART-B: MCS-043
Question 1:
A database Management system is to be created for a Study Centre to keep track of the students and the assignment
records of the students. The database records the date of submission of assignment, the date of evaluation, the date
of viva, the date of declaration of results, who evaluated the assignment, and the mark list description in which the
assignment marks were sent to Regional Office. The database also maintains the details of the evaluators. Please
perform the following activities for the description as given above.
(a) Design the database with suitable integrity constraints and create the database.
Answer
Table Name: stu_assignment_details
CREATE TABLE stu_assignment_details(assno number primary key,
stuno number(9), student_details(stuno),
stuname varchar(45),sem number(1) not null,
dos date not null,doev date,
doviva date,doresult date,evaluator varchar(45),
subject varchar(50) not null,mark number(3), not null,
remarks varchar(100));
Table Name: student_details
CREATE TABLE student_details(stuno number primary key,
stuname varchar(45) not null, yearofjoin char(4) not null,
addres varchar(50));
Table Name:Evaluator_details
CREATE TABLE evalulator_details(evalname varchar(50),empno number not null,
phonon number,address varchar(50),subject varchar(25),not null);
(b) Write the following queries using SQL:
(i) Find the List of the students who have not submitted even a single assignment.
ANSWER
SELECT stuname FROM student_details where stuno IN ( SELECT stuno FROM
stu_assignment_details);
(ii) Find the details of the evaluators by whom average marks awarded are more than 70%.
ANSWER
SELECT * FROM evaluator_details WHERE empno IN
( SELECT empno FROM stu_assignment_details WHERE mark >= 70);
(iv) Find the list of students who have not appeared in viva. Make and state suitable assumptions, if any.
ANSWER
SELECT stuno,stuname FROM stu_assignmet_detaisl WHERE dovi=NULL;
(c) Assume two views for the above table. The first view is for the data entry person who is only allowed to enter new
data in all the three tables, however, once he/she enters the data he/she is not allowed to modify it. Second for the
students who can see only the marks that he/she has obtained in his/her submitted assignments. Create the two views
and one user of the each view. Give the suitable access rights to the views/users.
ANSWER
CONNECT scott/tiger
SQL>CREATE VIEW assignmentview1 AS
SQL>SELECT * FROM stu_assign_details
SQL>CREATE USER staff IDENTIFIED BY
India123
User Created
SQL>GRANT CONNECT TO staff
Grant Succeed
SQL>GRANT resource to staff
Grant Succeed
SQL>GRANT SELECT ON assignview1 to staff
Grant Operation Successful.
SQL>CREATE USER student IDENTIFIED BY
Welcome123
User Created
SQL>GRANT CONNECT TO student
Grant Succeed
SQL>GRANT resource to student
Grant Succeed
SQL>GRANT SELECT ON assignview1 to student
Grant Operation Successful.
(d) Write a procedure that creates a mark list for the specified subject and evaluator. The mark list at the top
displays the subject code (course code) and title and the name of the evaluator. The details shown in the mark list are
– student ID, student name, student marks and equivalent grades. Please note that Grades are to be calculated from
marks by this procedure as per the following scheme –
>=75% and above A
>=60% and < 75% B
>=50% and <60% C
<50% F
ANSWER
CREATE PROCEDURE marklist(cc in varchra2,evalname varchar2)
DECLARE
Grade varchar(20);
BEGIN
FOR pro1 IN (SELECT * FROM stu_assignmnet_details
WHERE subject=cc and evaluator=evalname)
If (pro1.mark >= 75)then
Grade := ‘A’;
elsIf (pro1.mark >= 75 and pro1.mark<75 then
Grade := ‘B’;
elsIf (pro1.mark >= 75 and pro1.mark<60)then
Grade := ‘C’;
elsIf (pro1.mark >=50)then
Grade := ‘F’;
Else
Grade :=’No Mark’;
End if
Set SERVEROUTPUT ON
DBMS_OUTPUT.PUT_LINE(‘CORUSE CODE’ || cc);
DBMS_OUTPUT.PUT_LINE(‘’EVALULATOR NAME :’ || evalname);
DBMS_OUTPUT.PUT_LINE(‘ STUDENTNAME STUNAME MARK GRADE);
DBMS_OUTPUT.PUT_LINE(pro1.stuname||pro1.stuno||pro1.mark|pro1.grade);
END;
(e) Perform the following activities:
(i) Create a trigger that prints the assignment result of the student if he fails in that assignment.
ANSWER
CREATE TRIGGER stufail1
BEFORE INSERT OR UPDATE OF mark
ON scott.stu_assignment_details
FOR EACH ROW
BEGIN
If : new.nark < 50
DBMS_OUTPUT.PUT_LINE(‘The Students fail in the subject’);
Endif
END;
(ii) Create a trigger that automatically gives a grace of a maximum of 2%, if a student gets 48% marks in the
assignment. For example, if an assignment marks are entered as 48%, then the trigger will automatically convert the
marks to 50%, so is the case of student who gets 49% marks. His/her marks will be updated to 50% by the trigger.
ANSWER
CREATE TRIGGER stugrace
AFTER INSERT OR UPDATE OF mark
ON scott.stu_assignment_details
FOR EACH ROW
BEGIN
If : new.nark = 48 OR :new.mark = 49 then
UPDATE stu_assignment_details SET mark=50 WHERE rowed=last_insert_rowid();
Endif
END;
(f) Create a transaction to enter the mark list obtained from an evaluator of a specific assignment.
ANSWER
CREATE OR REPLACE PROCEDURE transc(assno number,stuno number(9),
stuname varchar,sem number,dos date,doev date,doviva date,doresult date,
evaluator varchar,subject varchar,mark number, remarks varchar)
IS
PRAGMA AUTONOMOUS TRANSACTION
BEGIN
INSERT INTO stu_assignment_details(assno,stuno,
stuname,sem,dos,doev,doviva,doresult,evaluator,
subject,mark, remarks) VALUE(assno,stuno, stuname,sem,dos,doev,doviva,doresult,evaluator,
subject,mark, remarks)
COMMIT;
END;
Question 1:
Write and demonstrate the UNIX commands for the following:
(a) Find the number of users currently logged in.
Answer
who
(b) Find the number of lines in a specified file.
Answer
wc – l filename
(c) Kill a background process.
Answer
kill processnumber
eg : kill 1000.
(d) Display the current environment variables.
Answer
set | less
(e) Change the file permissions to Read only for everyone on a data file created by you.
Answer
Chmod o+r file1
(f) Find the lines in a file that contains the string like b or ab or aab or aaab or aaaa…b
Answer
egrep -i “ab|aaaa|b|aaab” filename
(g) Transfer the names of all the files in a directory to a file.
Answer
cp -R /home/scripts /export/home/SIVA
(h) Display a file such that only 10 lines get displayed at one time.
Answer
Cat filename|head 10
(i) Create a file containing 10 lines, split it into two files containing 5 lines each.
Answer
split -l 5 file1.txt smallsplit.txt
(j) Display only those lines that are common in two different files.
Answer
$ comm -3 /path/to/file1/ /path/to/file2
Re: MCS-045 - UNIX And DBMS Lab - PART-A: MCS-043 Question 1(C) Posted On: 2/23/2010 5:18:33 PM
Question 1:
A database Management system is to be created for a Study Centre to keep track of the students and the assignment
records of the students. The database records the date of submission of assignment, the date of evaluation, the date of
viva, the date of declaration of results, who evaluated the assignment, and the mark list description in which the
assignment marks were sent to Regional Office. The database also maintains the details of the evaluators. Please
perform the following activities for the description as given above.
(c)Assume two views for the above table. The first view is for the data entry person who is only allowed to enter new
data in all the three tables, however, once he/she enters the data he/she is not allowed to modify it. Second for the
students who can see only the marks that he/she has obtained in his/her submitted assignments. Create the two views
and one user of the each view. Give the suitable access rights to the views/users.(4 Marks)
ANSWER
CONNECT scott/tiger
SQL>CREATE VIEW assignmentview1 AS
SQL>SELECT * FROM stu_assign_details
SQL>CREATE USER staff IDENTIFIED BY
India123
User Created
SQL>GRANT CONNECT TO staff
Grant Succeed
SQL>GRANT resource to staff
Grant Succeed
SQL>GRANT SELECT ON assignview1 to staff
Grant Operation Successful.
SQL>CREATE USER student IDENTIFIED BY
Welcome123
User Created
SQL>GRANT CONNECT TO student
Grant Succeed
SQL>GRANT resource to student
Grant Succeed
SQL>GRANT SELECT ON assignview1 to student
Grant Operation Successful.