PART-I : MCS-041

Q1. Write the UNIX commands for the following :

a) To display the disk usage of the directory and all its files.

Answer : - "du" command is used to find out the disk usage of the directory and all its files.

Syntax :
du [OPTION]... [FILE NAME]...
du [OPTION]... [DIRECTORY NAME]...

Example :
root@Notebook:~# du -a -h /shell

4.0K/shell/file1
4.0K/shell/prog1
4.0K/shell/prog2
4.0K/shell/prog3
20K/shell
root@Notebook:~#

Using “-a” option with “du” command displays the disk usage of all the files and directories.
Using “-h” option with “du” command provides results in “Human Readable Format“. Means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes etc.




b) To print the newline count, the byte count and the longest line length for any selected file.

Answer : - "wc" command allows you to count the number of lines, words, characters, and bytes of each given file or standard input and print the result.

Syntax :
wc [OPTION]... [FILE NAME]...

Example :
root@Notebook:~# wc -l -c -L /shell/prog1
49   834   40   /shell/prog1
root@Notebook:~#

The options below allow you to select which counts are printed.

  • -l--lines → Print the number of lines.
  • -w--words → Print the number of words.
  • -m--chars → Print the number of characters.
  • -c--bytes → Print the number of bytes.
  • -L--max-line-length → Print the length of the longest line.




c) To display the current date in the format mm/dd/yy (example: 09/04/09).

Answer : - "date" command is used to display the date in several formats.

root@Notebook:~# date +"%m/%d/%y"
09/11/20
root@Notebook:~#




d) To copy all the files containing “a” as starting file name to the directory assign3 using one command.

Answer : - Wildcards allow you to select filenames based on patterns of characters.

root@Notebook:~# cp /shell/a* /assign3
root@Notebook:~#

Examples of wildcard matching

PatternMatches
*All filenames
a*All filenames that begin with the character "a"
b*.txtAll filenames that begin with the character "b" and end with the characters ".txt"
Data???Any filename that begins with the characters "Data" followed by exactly 3 more characters
[abc]*Any filename that begins with "a" or "b" or "c" followed by any other characters
[[:upper:]]*Any filename that begins with an uppercase letter. This is an example of a character class.
[[:alpha:]]*Any filename that begins with an alphabetic characters.
[[:alnum:]]*Any filename that begins with an alphanumeric characters.
BACKUP.[[:digit:]][[:digit:]]This pattern matches any filename that begins with the characters "BACKUP." followed by exactly two numerals.
*[![:lower:]]Any filename that does not end with a lowercase letter.




e) Change the file permissions to read only for everyone other than you for a data file.

Answer : - To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user (u), group (g), or others (o) by adding (+) or subtracting (-) the read, write, and execute permissions.

root@Notebook:~# chmod go+r go-wx /shell/file1.txt
or
root@Notebook:~# chmod go=r /shell/file1.txt

There are two basic ways of using chmod to change file permissions: The symbolic method and the absolute form.

Symbolic Method

Access classOperatorAccess Type
u (user)+ (add access)r (read)
g (group)- (remove access)w (write)
o (other)= (set exact access)x (execute)
a (everyone or all : u, g, and o)

Absolute Form - The other way to use the chmod command is the absolute form, in which you specify a set of three numbers that together determine all the access classes and types. Rather than being able to change only particular attributes, you must specify the entire state of the file's permissions.

The three numbers are specified in the order : user (or owner), group, and other. Each number is the sum of values that specify read, write, and execute access :

PermissionNumber
Read (r)4
Write (w)2
Execute (x)1



f) To execute a task at lowest priority.

Answer : - Solve it Yourself




g) Compare two text files and display the differences.

Answer : -

root@Notebook:/shell# cat file1
Motherboard
Processor
RAM
Harddisk
SMPS
root@Notebook:/shell#

root@Notebook:/shell# cat file2
Motherboard
Keyboard
Mouse
Harddisk
Processor
root@Notebook:/shell#

root@Notebook:/shell# diff file1 file2
2,3c2,3
< Processor
< RAM
. . .
> Keyboard
> Mouse
5c5
< SMPS
. . .
> Processor
root@Notebook:/shell#




h) Use grep command to find and display the no. of times a particular pattern given by the user appeared in the file.

Answer : -

root@Notebook:~# grep -o "database" /shell/file1 | wc -l
5
root@Notebook:~#




i) Display last 10 lines of file1.

Answer : - "tail" command is used to display the last 10 lines (by default) of a file using standard output.

root@Notebook:~# tail /shell/prog1
or
root@Notebook:~# tail -10 /shell/prog1
Both commands are display the same output




j) To change the password of the user.

Answer : -

Change Password for current User Account

debabrata@Notebook:~# passwd
Changing password for debabrata
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
debabrata@Notebook:~#

Change Password for other User Account

To change password for other user you need to login as the root user.
root@Notebook:~# passwd amit
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@Notebook:~#




Q2. a) Write a series of UNIX commands that will produce a listing of the smallest 3 files (in size) in the current directory whose name starts with “a”.

Answer : - Coming Soon




Q2. b) Write a shell program that will search for patterns (i) “and” (ii) “to” in the text file file1 and display their count individually.

Answer : -

file="/shell/file1"
pattern="and"
patternLen=3
count=0
while read line
do
# Pick each line from the given file
line=`echo ${line}`
# Calculate the length of each line
len=${#line}
start=1
end=$patternLen
while test $end -le $len
do
s=`echo $line | cut -c$start-$end`
if [ "$s" = "$pattern" ]
then
count=`expr $count + 1`
fi
start=`expr $start + 1`
end=`expr $end + 1`
done
done < $file
echo "'and' Pattern Occurs $count times"
pattern="to"
patternLen=2
count=0
while read line
do
# Pick each line from the given file
line=`echo ${line}`
# Calculate the length of each line
len=${#line}
start=1
end=$patternLen
while test $end -le $len
do
s=`echo $line | cut -c$start-$end`
if [ "$s" = "$pattern" ]
then
count=`expr $count + 1`
fi
start=`expr $start + 1`
end=`expr $end + 1`
done
done < $file
echo "'to' Pattern Occurs $count times"

Output :
'and' Pattern Occurs 5 times
'to' Pattern Occurs 3 times


OR


file="/shell/file1"
`grep -o "and" $file | wc -l`
echo "'and' Pattern Occurs $count times"
`grep -o "to" $file | wc -l`
echo "'to' Pattern Occurs $count times"

Output :
'and' Pattern Occurs 5 times
'to' Pattern Occurs 3 times




Q2. c) Write a shell program to count and print the no. of uppercase and lowercase characters in a string given by the user.

Answer : -

echo "Enter the string..."
read text
len=${#text}
uppercase=0
lowercase=0
for((i=1;i<=len;i++))
do
ch=`echo $text | cut -c$i`
# Count number of Uppercase Character present in the given String
case $ch in
[ABCDEFGHIJKLMNOPQRSTUVWXYZ])
uppercase=`expr $uppercase + 1`
;;
esac
# Count number of Lowercase Character present in the given String
case $ch in
[abcdefghijklmnopqrstuvwxyz])
lowercase=`expr $lowercase + 1`
;;
esac
done
echo "Number of Uppercase Character Present in the String = $uppercase"
echo "Number of Lowercase Character Present in the String = $lowercase"




Q2. d) Write a shell program to take a file consisting of characters and other symbols as a source file and direct the characters to file charc-file and other symbols to sym-file.

Answer : -

echo "Enter the file name....."
read sourceFile
if test -r $sourceFile
then
`touch /shell/charc-file`
`touch /shell/sym-file`
characterFile="/shell/charc-file"
symbolFile="/shell/sym-file"
while read line
do
# Pick each line from the given file
line=`echo ${line}`
# Calculate the length of each line
len=${#line}
for((i=1;i<=len;i++))
do
ch=`echo $line | cut -c$i`
ascii=`echo $ch | od -An -t dC | awk '{print $1}'`
if [ $ascii -ge 65 -a $ascii -le 90 ] || [ $ascii -ge 97 -a $ascii -le 122 ] || [ $ascii -ge 48 -a $ascii -le 97 ] || [ $ascii -eq 32 ]
then
`echo $ch >> $characterFile`
else
`echo $ch >> $symbolFile`
fi
done
done < $sourceFile
else
echo "$sourceFile is not exist or not have read permission"
fi






PART-II : MCS-043

Q1. Consider a Super-market and perform the following :

a) Draw an enhanced entity relationship (EER) diagram.

Answer : - Coming Soon




Q1. b) Create the complete database.

Answer : - Coming Soon




Q1. c) Normalize till required normal forms.

Answer : - Coming Soon




Q1. d) Write all the relational schemas.

Answer : - Coming Soon




Q1. e) Write the following queries using SQL :

(i) To display all the products from Hindustan Lever.

Answer : - Coming Soon


(ii) To display all the food processor brands (company-name) available in the super market.

Answer : - Coming Soon


(iii) To display the models and their price for the item FAN, in ascending order of price.

Answer : - Coming Soon


(iv) Create a view of the sales for the manager showing overall performance week-wise.

Answer : - Coming Soon




Q1. f) Create a trigger that prints the daily catalogue on change of a price of any cosmetic item.

Answer : - Coming Soon




Q1. g) Create a trigger whenever there is a new entry (of a new model) in the food processors. Also design a trigger whenever there is a deletion of the record too.

Answer : - Coming Soon




Q1. h) Create a report that shows the overall revenue generated, week-wise.

Answer : - Coming Soon