COMP301Lab05 - Lab Exercise 5 PDF

Title COMP301Lab05 - Lab Exercise 5
Author Rukshar Patel
Course Unix/Linux Operating Systems
Institution Centennial College
Pages 2
File Size 98.7 KB
File Type PDF
Total Downloads 97
Total Views 147

Summary

Lab Exercise 5 ...


Description

Introduction to Operating System Concepts and Unix (COMP301)

Centennial College

As s i gnme n t5-Bas i c sofBas hs c r i p t i ng Due :Fe br uar y2 1, 20 14a t1 7 : 0 0 Objective: To explore the basics of Bash scripting.

Bash Shell Script Programming Assignment Copy your scripts below each question. Upload your assignment as lastname_firstname_Assignment05 to the digital dropbox.

Question 1. Write a script that would accept the two strings from the console and would display a message stating whether the accepted strings are equal to each other. Answer: echo -n "Enter string 1 : " read str1 echo -n "Enter string 2 : " read str2 if [ "$str1" = "$str2" ] then echo "Strings are equal" else echo "Strings are not equal" fi

Question 2. Write a Bash script domain2ip that takes a list of domain names and displays their IP addresses. Use the nslookup command. nslookup www.google.com nslookup www.hotmail.com nslookup www.gmail.com nslookup www.twitter.com nslookup www.studentweb.cencol.ca

Assignment 5

Page 1 of 2

Introduction to Operating System Concepts and Unix (COMP301)

Centennial College

Question 3. Write a Bash script that takes the side of a cube as a command line argument and displays the volume of the cube.

Answer: echo -n "Enter the side of cube :" read sideOfCube let X=sideOfCube*sideOfCube*sideOfCube echo $X

Question 4. Write a Bash script that prompts you for a user ID and displays the corresponding user’s login name, owner’s name, and his/her home directory. Note: this info can be found in the /etc/passwd file.

Answer: echo -n "Enter user id : " read userid if userloginname=`grep ":$userid:" /etc/passwd | cut -f1 -d :` userloginname=`grep ":$userid:" /etc/passwd | cut -f1 -d :` username=`grep ":$userid:" /etc/passwd | cut -f5 -d :` homedirectory=`grep ":$userid:" /etc/passwd | cut -f6 -d :` then echo "user login name : $userloginname" echo "user name : $username" echo "user Home directory : $homedirectory" fi

Assignment 5

Page 2 of 2...


Similar Free PDFs