Lab Assessment: - 1: 1.create A Virtual Machine (VM)
Lab Assessment: - 1: 1.create A Virtual Machine (VM)
Lab Assessment: - 1: 1.create A Virtual Machine (VM)
7. cat file1 file2 > file3:Joins two files (file1, file2) and stores the output in a
new file (file3)
20.who-option’’s: displays the user that are currently kogged into your
unix computer system.
SHELL PROGRAMMING -1
1) Write Script to see current date, time, username, and current directory.
2) How to write shell script that will add two numbers, which are supplied as
command line argument, and if this two numbers are not given show error and
its usage.
if [ $# -ne 2 ]
then
echo "Usage - $0 x y"
echo " Where x and y are two nos for which I will print sum"
exit 1
fi
echo "Sum of $1 and $2 is `expr $1 + $2`"
3)Write Script to find out biggest number from given three nos. Numbers are
supplied as command line argument. Print error if sufficient arguments are not
supplied.
CODE:read a b c
if [[ $a == 0 || $b == 0 || $c == 0 ]]; then
echo "command line arguments are missing"
elif [[ $a == $b && $b == $c ]]; then
echo "All the three numbers are equal"
elif [[ $a == $b && $b > $c || $b == $c && $c > $a || $a == $c && $a > $b ]]; then
echo "I cannot figure out which number is biggest"
else
if [[ $a > $b && $a > $c ]]; then
echo "$a is Biggest number"
elif [[ $b > $a && $b > $c ]]; then
echo "$b is Biggest number"
else
echo "$c is Biggest number"
fi
fi
4. Write script to print the following numbers as 5,4,3,2,1 using while loop.
i=5
while test $i != 0
do
echo "$i
"
i=`expr $i - 1`
done
echo -----------------------------------------------------
echo -----------------------------------------------------
read a
read b
echo 1.Addition
echo 2.Subtraction
echo 3.Multiplication
echo 4.Division
echo 5.Modules
echo Enter your choice
read choice
case $choice in
esac
6. Write script to print given number in reverse order, for eg. If no is 123 it
must print as 321
CODE:
echo "enter the number "
read num
while [ $num != 0 ]
do
d=$(($num % 10 ))
num=$(($num/ 10 ))
rev=$( echo ${rev}${d} )
done
echo $rev is in reverse
7. Write script to print given numbers sum of all digit, For eg. If no is 123 it's
sum of all digit will be 1+2+3 = 6.
CODE:
8. Write script to determine whether given file exist or not, file name is supplied as
command line argument, also check for sufficient number of command line argument.
if [ $# -ne 1 ]
then
echo "Usage - $0 file-name"
exit 1
fi
if [ -f $1 ]
then
echo "$1 file exist"
else
echo "Sorry, $1 file does not exist"
fi
11.Write a shell script that takes a name of a folder, and delete all sub folders
of size 0.
ls $1 |
while read folder
do
files=`ls $folder | wc –l`
if [ files –eq 0 ]
then
rmdir $folder
fi
done
12. write a shell script that will take an input file and remove identical lines (or
duplicate lines from the file)