NIT1202 Operating Systems, Semester 2: UNIX Script Assignment

Verified

Added on  2020/05/08

|11
|832
|38
Homework Assignment
AI Summary
This document presents a complete solution to a UNIX script assignment, specifically focusing on the Bourne Again Shell (Bash) scripting language. The assignment is divided into several parts, including a script to display system information such as the home directory, path, user ID, login shell, and current date and time. Another section involves a script designed to generate a specified number of random numbers within a user-defined range, along with a requirement to calculate the difference between the random numbers. The solution also includes scripts to identify and display the highest and lowest numbers from the generated random numbers. The document showcases the code, the program output, and a bibliography of relevant sources. The assignment is designed to provide a comprehensive solution for students to understand and learn the concepts of shell scripting and operating systems.
Document Page
Running head: NIT1202 OPERATING SYSTEMS
UNIX Script Assignment 1: Part II
Semester 2, 2017
Name of the Student
Name of the University
Author’s Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1
NIT1202 OPERATING SYSTEMS
Table of Contents
1. Bourne Again Shell Script...........................................................................................................2
1.1. Print the information: the home directory, path, userid, login shell together with the
current date and time...................................................................................................................2
1.2. Shell program to display eight random number between range inputted by the user with
difference of 100..........................................................................................................................3
1.3. Printing the highest and the lowest numbers of the generated eight random numbers........4
1.4. Exit the program...................................................................................................................6
Output Results.................................................................................................................................7
Bibliography..................................................................................................................................10
Document Page
2
NIT1202 OPERATING SYSTEMS
1. Bourne Again Shell Script
1.1. Print the information: the home directory, path, userid, login shell together with
the current date and time
#!/bin/bash
#Author's Name: Kiran Gautam
#Student_ID s458158
#Date: Oct 2017
#This script generates different information such as
# home directory, path, userid, login
# shell with the current date and time
# function for displaying a line of asterics
echo "Please choose any of the options"
option=("Option 1" "Option 2" "Option 3" "Option 4")
select option in "${option[@]}"
do
function ln(){
echo "*******************************"
}
Document Page
3
NIT1202 OPERATING SYSTEMS
case $option in
"Option 1") clear
echo "Display the home directory : $(ls)"
ln # function called
echo "Diplay the path : $(echo $PATH)"
ln
echo "userid : $(id -u)"
ln
echo "login shell with current date and time:"
who
ln ;;
1.2. Shell program to display eight random number between range inputted by the
user with difference of 100
"Option 2")
#This script is created to accept a range
#from user and diplay eight random numbers between the range
#Author: Student_Name Kiran Gautam
#Student_ID s458158
#Date: Oct 2017
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4
NIT1202 OPERATING SYSTEMS
echo "Enter the range and the difference must be 100:"
read upper
read lower
ln
echo "The random numbers between the range $upper and $lower is as follows: "
IFS=$'\n'
num=($(shuf -i $upper-$lower -n 8))
printf "%s\n" "${num[@]}"
ln
;;
1.3. Printing the highest and the lowest numbers of the generated eight random
numbers
"Option 3")
#The shell script is created for diplaying
#maximum and the minimum number from the random numbers
#generated in the above option
#Author's Name: Kiran Gautam
#Student_ID s458158
#Date: Oct 2017
Document Page
5
NIT1202 OPERATING SYSTEMS
echo "The random numbers generated are as follows:"
IFS=$'\n'
#num=($(shuf -i $upper-$lower -n 8))
printf "%s\n" "${num[@]}"
ln
minimum=${num[0]}
maximum=${num[0]}
# Loop for the elements in the created array
for i in "${num[@]}"
do
# Printing the minimum number from the range
if [[ "$i" -lt "$minimum" ]]; then
minimum="$i"
fi
# Printing the maximum number from the range
if [[ "$i" -gt "$maximum" ]];
then
maximum="$i"
Document Page
6
NIT1202 OPERATING SYSTEMS
fi
done
echo "The lower number from the range is: $minimum"
ln
echo "The highest number from the range is: $maximum"
ln
;;
1.4. Exit the program
"Option 4")
#This shell script exits the loop
#Author's Name: Kiran Gautam
#Student_ID s458158
#Date: Oct 2017
break
;;
*) echo "Entry is invalid"
;;
esac
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7
NIT1202 OPERATING SYSTEMS
done
Output Results
Document Page
8
NIT1202 OPERATING SYSTEMS
Document Page
9
NIT1202 OPERATING SYSTEMS
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
10
NIT1202 OPERATING SYSTEMS
Bibliography
Dodis, Y., Pointcheval, D., Ruhault, S., Vergniaud, D., & Wichs, D. (2013, November). Security
analysis of pseudo-random number generators with input:/dev/random is not robust. In
Proceedings of the 2013 ACM SIGSAC conference on Computer & communications
security (pp. 647-658). ACM.
Kochan, S. G., & Wood, P. (2016). Shell Programming in Unix, Linux and OS X. Addison-
Wesley Professional.
Stevens, W. R., & Rago, S. A. (2013). Advanced programming in the UNIX environment.
Addison-Wesley.
chevron_up_icon
1 out of 11
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]