Lab 2: Search and Report Solution

$30.00 $24.90

You'll get a: . zip file solution, download link after Payment

Description

Introduction

Lab 2 is an opportunity to use a number of UNIX/Linux tools to search subdirectories, report the nature of files found and produce a summary report.

  • There is a bit less hand-holding in this lab than in the previous lab. Refer back to the Lab 1 writeup if you have forgotten anything important.

lu13750uytl2d tmp ad9ec41292a5bfd6

Requirements

Your script shall be named srpt and be marked executable. Here is how you execute your script:

lu13750uytl2d tmp 624962add8748e47

./srpt PATH

Example

lu13750uytl2d tmp 490eceedcfaebd31

./srpt ./testfolder

Your script shall inspect the file names of every file and directory in the folder represented by PATH and accumulate a count of each of the following file system objects:

Every file

lu13750uytl2d tmp ac5d6869f540dc85

Every subdirectory (excluding “PATH” itself)

lu13750uytl2d tmp ac5d6869f540dc85

Every symbolic link

lu13750uytl2d tmp ac5d6869f540dc85

Every file that is 365 days old or older (old files)

lu13750uytl2d tmp ac5d6869f540dc85

Every file that is larger than 500,000 bytes (large files)

lu13750uytl2d tmp ac5d6869f540dc85

Every graphics file (any file with suffix of .jpg, .gif or .bmp)

lu13750uytl2d tmp ac5d6869f540dc85

Every temporary file (any file with a suffix of “.o”)

lu13750uytl2d tmp ac5d6869f540dc85

Every executable file (any file executable by the user)

lu13750uytl2d tmp ac5d6869f540dc85

Total byte count of each file

lu13750uytl2d tmp ac5d6869f540dc85 lu13750uytl2d tmp 7ef32679646b737

Your srpt script shall produce a report in this format in this order (note the exact spelling of the labels, the spacing and the commas in the numbers):

lu13750uytl2d tmp c78762296414897e SearchReport host path date

Execution time nnn

Directories n,nnn,nnn

Files n,nnn,nnn

Sym links n,nnn,nnn

Old files n,nnn,nnn

Large files n,nnn,nnn

Graphics files n,nnn,nnn

Temporary files n,nnn,nnn

Executable files n,nnn,nnn

TotalFileSize n,nnn,nnn

lu13750uytl2d tmp 7ef32679646b737

Your srpt script should exit with return code 0 (zero) after producing its report unless the path was not specified on the commandline. If your script is executed without a PATH, issue this usage statement and exit with return code 1:

lu13750uytl2d tmp 624962add8748e47

Usage: srpt PATH

Additional Requirements

You are free to use whatever tools that are available in order to produce the requested output. Please note the following:

You may only make one pass over the files per execution of your script (meaning no multiple file system searches). The find command is the best utility to obtains all of the required information in a single execution of find . Search the Internet for examples on how to use find to search and count files of a given name or type and save that information in a temporary file.

lu13750uytl2d tmp ac5d6869f540dc85 lu13750uytl2d tmp 3395c2c1d118b120 lu13750uytl2d tmp 3395c2c1d118b120

You may not modify any file or directory in the requested path. If you create any temporary files, do so only in a unique folder you create, in /tmp . I recommend creating a folder in /tmp with your icarus userID IN YOUR SCRIPT so that its name is unique.

lu13750uytl2d tmp ac5d6869f540dc85 lu13750uytl2d tmp 3395c2c1d118b120

Example

mkdir /tmp/$USER at the top of your script will create a folder named /tmp/dj45678 if my icarus userID happened to be dj45678 . The $USER variable is always set to the current userID. Create all of your temporary files in this folder.

At the end of your script, delete your /tmp folder with all of your temporary files. Be a good computer citizen, and do not expect that any files or folders in /tmp will still be there the next day. This is why it is called /tmp .

lu13750uytl2d tmp ac5d6869f540dc85 lu13750uytl2d tmp ffd869dd66300848 lu13750uytl2d tmp 3395c2c1d118b120

CS 3030 Cowan 01-04-2019 08:43 PM 2

Do not “prompt” the user to enter any information. Supply only the name of the folder on the commandline.

lu13750uytl2d tmp ac5d6869f540dc85

Use self-documenting variables to hold the counts.

lu13750uytl2d tmp ac5d6869f540dc85

Format counts with commas for readability. Look up the printf command, which can output numbers with commas.

lu13750uytl2d tmp ac5d6869f540dc85

Output the date in the report header as produced by the date utility. Use the BASH variable $HOSTNAME to print the hostname in the report header. Here is an example output from date:

lu13750uytl2d tmp 2fdb1c76127e8259 lu13750uytl2d tmp ac5d6869f540dc85

Thu Dec 25 07:00:00 MST 2014

Execution time is calculated from invocation and ends just before printing the summary report.

lu13750uytl2d tmp ac5d6869f540dc85

Use whitespace and indenting to make your script readable.

lu13750uytl2d tmp ac5d6869f540dc85

Add comments to your script to document your logic.

lu13750uytl2d tmp ac5d6869f540dc85

Clone your private repo on github.com

In the assignment module in Canvas, find the link to the Canvas page entitled “Clone your Lab 2 Repo”, click on it and follow the instructions.

lu13750uytl2d tmp 8b73181456655b7

Use git to clone (download) a copy of your private repo to your local machine

To obtain a copy of your private repo to icarus, log into icarus and enter these commands:

lu13750uytl2d tmp 691e5b24cf8abe39

BASH

git clone https://cowancs3030spring19/lab2-YOURGITHUBUSERNAME

cd lab2-YOURGITHUBUSERNAME

Write and test srpt

Fire up your favorite text editor, and begin with your header:

lu13750uytl2d tmp 8579c6c44f6fe724

BASH

#!/bin/bash

  • (Your name)

  • Lab 2 – Search and Report

  • CS 3030 – Scripting Languages

(Add your great code here)

lu13750uytl2d tmp 1d8e68d1f441f668

Be sure to save your script as srpt .

CS 3030 Cowan 01-04-2019 08:43 PM 3

As you add features, test your script with a folder of file system objects, provided on icarus for your convenience:

lu13750uytl2d tmp 2fdb1c76127e8259 lu13750uytl2d tmp ac5d6869f540dc85

./srpt /var/classes/cs3030/lab2/testfiles

Your script must successfully complete scanning the testfiles folder in 5 seconds or less.

Here is an EXAMPLE of what your script might produce (the date of course will be different).

lu13750uytl2d tmp 5bdccf1a7aa52fe2

Test your program using Cucumber

lu13750uytl2d tmp 624962add8748e47

./cucumber -s

lu13750uytl2d tmp 28d9cb1173cc5431

  • Cucumber for this lab generates a random set of file system objects to fully test your program.

Submit your assignment code for grading

  • Remember, you must push your script in your private repo to github.com to receive any points, for all assignments in this course.

lu13750uytl2d tmp 1e7b8dcf57c07944

BASH

git add srpt

git commit -m“COMMIT MESSAGE”

git push origin master

Files created for this lab: srpt

Grading

Here is how you earn points for this assignment:

CS 3030 Cowan 01-04-2019 08:43 PM 4

lu13750uytl2d tmp 7aa3d02dd92f3ea5

FEATURES

POINTS

Must-Have Features

Script is named correctly and found in its proper place in your repo

10

Script is executable

10

Required Features

Report header is in the correct format

10

Execution time is reported in seconds

10

Execution time is < 5 seconds for ./testfiles

40

Directory count is correct

10

File count is correct

10

Sym link count is correct

10

Old file count is correct

10

Large file count is correct

10

Graphics file count is correct

10

Temporary file count is correct

10

Executable file count is correct

10

Total file size is correct

10

Exit code is zero for normal execution

10

Exit code is 1 if the PATH is not specified on the commandline

10

A “Usage” statement is printed if the PATH is not specified on the commandine

10

Grand Total

200

CS 3030 Cowan 01-04-2019 08:43 PM

5