Starting from:

$40

Shell Programming CSC 4103: Operating Systems Programming Assignment 3:Solved

Programming Assignment 3: Shell Programming CSC 4103: Operating Systems

Total Points:  10 

Instructions: Compile and test-run your code on the classes server. Submit your work as instructed and verify your submission. The verify command will display your submission date/time. Include your name and classes account in all source code files. Necessary documentation should be included to instruct how to compile and run your code. Late submissions will be penalized at the rate of 10% per day late and no more than 3 days late.  

 

Objective

To learn the use of Bash shell programming.  

 

Background 
The shell scripting is a powerful tool to execute a batch of Unix commands for completing a complicated task. In the class, we have learned the basics of Bash Shell programming. This project is a programming practice to use shell for a simple file processing.  

 

Programming Task 
Download the tar ball at the link http://www.csc.lsu.edu/~fchen/class/csc4103-sp19/ assignments/lfw.tgz, which is a subset of an image database from UMass [1]. Download and untar the package, which creates a directory. This directory contains a set of subdirectories, each of which contains one or more images. This directory of files will be used as your test input. You need to write a shell script (batch_tar.sh) to process the files by the guideline below.

 

1.     Your script should provide help information. Typing command “%./batch_tar.sh help” should print help info to explain how to use the script.

 

2.     The shell script batch_tar.sh should accept two parameters to allow users to specify the input directory of the files and the output directory. An example command:  

 

%./batch_tar.sh <input_dir <output_dir 

 

 

3.     The output directory should be created by your script and should have the same directory structure as the input directory.

 

4.     For each file in the input directory, the script should produce a compressed tar file with proper naming in the corresponding output path. For example, for image foo.jpg should be named as foo.tgz. The file should be placed in the same subdirectory in the output directory, just like the original image.  

For example, if the original file is input_dir/foo/test.jpg, the output file should be output_dir/foo/test.tgz.

 

5.     After a file has been processed, print a line of processing info to show (1) the name of the original file, (2) the size of the original file, (3) the name of the tar file, (4) the size of the tar file.  

 

6.     After all images have been processed, print summary info to show (1) the total number of original files being processed, (2) the total size of original files, (3) the total number of the tar files, and (4) the total size of the tar files.   

 

7.     Your script must use functions to organize your code.  

 

 

Additional Hints 
(1)  Use the following command to download and unzip the tar ball.  

$ wget http://www.csc.lsu.edu/~fchen/class/csc4103-sp19/assignments/lfw.tgz 

$ tar -zxvf lfw.tgz 

 

(2)  Use the following command to compress a file to a tar ball.  

$ tar –zcvf <tar file <original file 

For example, we can use the command “$ tar –zcvf foo.tgz foo.jpg” to compress the file foo.jpg.  

 

(3)  Use the following command to extract the first half of the file name.  

$ echo <file name | cut -d '.' -f 1 

For example, the command “% echo foo.jpg | cut -d '.' -f 1” will output foo.  

 

(4)  Use the following command to get the file size in bytes.  

$ wc -c  <file name | awk '{print $1;}'  

(5)  Use man to get extra help info about the commands.  

 

 

Submitting Your Work 
All files you submit must have a header with the following:  

Name:  
 
Your Name (Last, First)
Project:
 
PA-3 (Shell Programming)
File:      
 
filename  
Instructor:
 
Feng Chen
Class:   
 
cs4103-sp19
LogonID:
 
cs4103xx
 

You need to use the server “classes.csc.lsu.edu” to work on the assignment. You can login to your account in the server using SSH. Create a directory prog3 (by typing mkdir prog3) in your home directory in which you create your program or source code.  

 

 

Note that do NOT include any directory in prog3.  

 

Make sure that you are in the prog3 directory while submitting your program. Submit your assignment to the grader by typing the following command:  

 

         ~cs4103_chf/bin/p_copy 3 

 

This command copies everything in your prog3 directory to the grader’s account. Check whether if all required files have been submitted successfully:

 
         ~cs4103_chf/bin/verify 3 


 

More products