Amisha Linux File
Amisha Linux File
Practical File
Page 1 of 33
INDEX
S. TITLE Page Remarks/Signature
No. No.
Page 2 of 33
5. Design and implement a shell script that 14
computes the gross salary of a employee
according to the following rules:
Page 3 of 33
The second argument, which is optional,
can be used to specify in which the search
is to begin in current working directory, In
either case, the starting directory as well as
all its subdirectories at all levels must be
searched. The script need not include any
error checking
Page 4 of 33
password as confirmation and if match
occurs it must lock the keyword until a
matching password is entered again by the
user ,note that the script must be written to
disregard BREAK, control-D. No time
limit need be implemented for the lock
duration.
Page 5 of 33
1. Design, develop and implement a shell script that accepts a path name
and creates all the components in the path name as directories (ex:
a/b/c/d should create a directory a, a/b, a/b/c, a/b/c/d.)
Solution: -
#!/bin/sh
read p
i=1
j=1
do
mkdir $x
cd $x
pwd
j=`expr $j + 1`
i=`expr $i + $namelength`
echo $g
done
Page 6 of 33
OUTPUT
Page 7 of 33
2. Design, develop and implement a shell script that accepts two file
names as arguments, checks if the permissions for these files are
identical and if the permissions are identical, output common
permissions and otherwise output each file name followed by its
permissions.
Solution: -
#!/bin/bash
if [ $# -ne 2 ]
then
exit
fi
read f1
read f2
if [ $p1 = $p2 ]
then
echo $p1
else
Page 8 of 33
echo permission of file $f2 is $p2
fi
OUTPUT
Page 9 of 33
3. Design, develop and implement a shell script to find out biggest
number from given three nos. Numbers are supplied as command line
arguments. Print error if sufficient arguments are not supplied.
Solution: -
#!/bin/bash
read a b c
i=$a
then
i=$b
fi
then i=$c
fi
Page 10 of 33
OUTPUT
Page 11 of 33
4. Design, develop and implement a shell script that takes a valid
directory name as an argument and recursively descend all the
subdirectories find its maximum length of any file in that hierarchy
and writes this maximum value to the standard output.
Solution: -
#!/bin/bash
for i in $*
do
if [ -d $i ]
then
echo `ls -Rl $1 | grep "^-" | tr -s ' ' | cut -d' ' -f 5,8 | sort -n
| tail -1`
else
fi
done
Page 12 of 33
OUTPUT
Page 13 of 33
5. Design and implement a shell script that computes the gross salary of
an employee according to the following rules:
i) If basic salary is <1500 then HRA=10% of the basic and
DA=90% of the basic
ii) If the basic salary is>=1500 then HRA=500/- and DA=98% of
the basic
Solution: -
#!/bin/bash
read bs
then
then
hra=500
fi
Page 14 of 33
OUTPUT
Page 15 of 33
6. Design, Develop and implement an interactive file –handling shell
program. Let it offer the user the choice of copying removing,
renaming, or linking files. Once the user has made a choice, have the
same program ask the user for the necessary information, such as the
file name, new name and so on.
Solution: -
#!/bin/bash
echo "*******MENU*********"
echo "
1. List of files.
2. Copying files.
3. Removing files.
4. Renaming files.
5. Linking files."
read -r k
case $k in
ls -l ;;
read -r ofile
read -r nfile
Page 16 of 33
3 ) echo "Enter the file name to remove."
read -r rfile
read -r ofile
read -r nfile
mv "$ofile" "$nfile" && echo "The file $ofile name renamed to $nfile." ||
echo "You cann't Rename the file. " ;;
read -r ofile
read -r lfile
ln "$ofile" "$lfile " && echo "Create the linking file Sccessfully." || echo
"You cann't Linking the file.";;
*)
esac
Page 17 of 33
OUTPUT
Page 18 of 33
Page 19 of 33
Page 20 of 33
7. Design, Develop and implement a shell script to perform the following
string operations:
a). To extract a sub-string from a given string.
b). To find the length of a given string.
Solution: -
#!/bin/sh
read str
strlen=${#str}
read s1
read f1
Page 21 of 33
OUTPUT
Page 22 of 33
8. Design, Develop and implement a shell script that display all the links
to a file specified as the first argument to the script. The second
argument, which is optional, can be used to specify in which the search
is to begin in current working directory, in either case, the starting
directory as well as all its subdirectories at all levels must be searched.
The script need not include any error checking.
Solution: -
#!/bin/sh
if [ $# -eq 1 ]
then pwd>tm
cat tm
else
tm=$2
echo "$tm"
fi
cat t2
Page 23 of 33
OUTPUT
Page 24 of 33
9. Design, Develop and implement a shell script that reports the logging
in of a specified user within one minute after he/she logs in. The script
automatically terminates if the specified user does not login during a
specified period of time.
Solution: -
#!/bin/sh
read user
period=0
while[true]
do
var='who|grep -w "$user"
len='echo "$var"|wc-c'
if[$len -gt 1]
then
exit
else
sleep 1
tm='expr $tm+1'
fi
then
exit
Page 25 of 33
fi
done
OUTPUT
Page 26 of 33
10. Design, Develop and implement a shell script that folds long lines into
40 columns. Thus, any line that exceeds 40 characters must be broken
after 40th; a\ is to be appended as the indication of folding and the
processing is to be continued with the residue. The input is to be
through a text file created by the user.
Solution: -
#!/bin/sh
read fn
do
lgth=`expr $lgth - 1`
s=1;e=5
if [ $lgth -gt 40 ]
then
do
s=`expr $e + 1`
e=`expr $e + 40`
done
echo $ln
Page 27 of 33
fi
done
OUTPUT
Page 28 of 33
11. Design, Develop and implement a shell script to implement terminal
locking (similar to the lock command) .it should prompt the user for
the password .after accepting the password entered by the user it must
prompt again for the matching password as confirmation and if match
occurs it must lock the keyword until a matching password is entered
again by the user ,note that the script must be written to disregard
BREAK, control-D. No time limit need be implemented for the lock
duration.
Solution: -
#!/bin/sh
clear
stty -echo
read pass1
read pass2
if [ "$pass1" = "$pass2" ]
then
trap ``/1 2 3 9 15 18
while true
do
read pass3
if [ $pass1 = $pass3 ]
Page 29 of 33
stty echo
exit
else
fi
done
else
stty echo
fi
Page 30 of 33
OUTPUT
Page 31 of 33
12. Design, Develop and Implement a shell script that delete all lines
containing a specific word in one or more file supplied as argument to
it.
Solution: -
#!/bin/sh
if[$# -eq 0]
then
echo"no arguments"
else
read y
for i in $*
do grep -v "$y""$i">temp
if[$? -ne 0]
then
else
cp temp $i
rm temp
fi
done
fi
done
Page 32 of 33
OUTPUT
Page 33 of 33