CEG 233: Linux and Windows

Lab on Scripting: First of Two

Table of Contents

  1. Educational Objectives
  2. Background
  3. Lab Experiment
  4. Acknowledgements
  5. References

Educational Objectives

The objectives of this lab experiment are to make you :

  1. Familiar with a few command line utilities both in Linux and Windows
  2. Learn fundamentals of Linux Bash scripting
  3. Learn fundamentals of Windows PowerShell scripting

Background

This is the first of two labs on scripts. This lab is about invoking programs interactively, and writing short little procedures. The second one is about more involved scripting. Both labs ask you do something in Bash and again in PowerShell. It is up to you whether you do the scripts first or second in PowerShell. In general, whatever is possible to do in PowerShell is also possible to do in Bash and vice versa, but the relative levels of ease may be different.

Note the Required Readings listed in the References.

Lab Experiment

All work is expected, but not required, to be carried out in the Operating Systems and Internet Security (OSIS) Lab, 429 Russ. But, you are welcome to work wherever. Note that use of both Linux and Windows and other software, that may not always be installed in other facilities, may be needed.

This lab depends on the following topics covered in the following lectures: file name regular expressions, procedures in Bash and PowerShell, Bash script file details, and PowerShell script file details. Before beginning to work on this lab, you must have read the notes on Bash and PowerShell given in the References.

  1. Linux Bash Pipeline Construction: Construct a pipeline with two pipes and an input redirection and an output append-redirection as in:
    (c1 | 2 | c3 ) < inputInfo.txt >>outputCollection.txt
    The above should be "useful", and you are choosing what the c1, c2, and c3 are and their arguments, if any. [Hint: Re-read Min list of Linux commands.] Explain what your pipeline construction does in the answers.txt file.
  2. Linux Bash cleanUp.sh Script: This is about keeping a directory free of "junk" files. To be specific, we want to remove files that are backups and auto-saved versions.
    1. Develop a Bash procedure called cleanUp() that deletes all backup and auto-save files from the given directory . Assume that names of back up files end in either (i) ~ or (ii) .bak, and (iii) auto-save files have names beginning with a #.
    2. Develop a test harness that tests the cleanUp() procedure. The test() procedure should (i) create a new directory named TEST in the current directory, create a few files (say a dozen each of names chosen by you) that fit the three categories of junk files in TEST, (ii) list-long the TEST directory, (iii) invoke cleanUp TEST, and again (iv) list-long the TEST directory.
  3. In Windows PowerShell Pipeline Construction: Construct a pipeline with two pipes and an output append-redirection as in:
    c1 | c2 | c3 >> outputCollection.txt
    This need not be the same as what you did in Linux above, but should be "useful", and you are choosing what the c1, c2, and c3 are and their arguments, if any. Explain what your pipeline construction does in the answers.txt file.
  4. In Windows: Develop scripts cleanUp.ps1 and testScript.ps1 equivalent to the above in the PowerShell syntax. Use standard commands that come with Windows, not the ones in cygwin.
  5. Comment on the levels of ease comparing Bash with PowerShell in each of the above tasks. Include the commentary in the answers.txt file.
  6. Suppose we wish to compare the performance of cleanUp in Bash versus PowerShell. Describe how this can be done objectively. Include this in the answers.txt file.

Turnin

Note the number <n> of this Lab from the course home page and use L<n> as the first argument to turnin. In addition to the text input files, and the script files you created, turn in the file called myLabJournal.txt, and the usual ReadMe.txt and answers.txt as explained in Expectations.


Acknowledgements


References

  1. Prabhaker Mateti, Notes on Scripting with Bash, scriptingWith Bash.html. This article is more specific to our labwork than Sobell's book. Required Reading.
  2. Prabhaker Mateti, Notes on Scripting with PowerShell, scriptingWith PowerShell.html. This article is specific to our lab work. Required Reading.
  3. ..\..\Slides\PowerShell_reference.pptx Mainly for instructor's use.
  4. Sarah Gothard, Table of Bash-PowerShell-Features, 2010. bashVsPowerShellTable.html. Required Reading.

Grading Sheet for CEG 233: Linux and Windows
Lab on Scripting: First of Two

Weight 5%
Instructor: Prabhaker Mateti
Grader:
Student LoginID Bonus Points
Item description MaxPts Points
ReadMe.txt, answers.txt and myLabJournal.txt are submitted with expected content 05 .
Bash pipeline construction: works (5 points), useful (5 points), clever (5 bonus points) 10 .
Bash cleanUp() Delete all backup and auto-save files. 10 .
Bash test harness 10 .
PowerShell pipeline construction: works (5 points), useful (5 points), clever (5 bonus points) 10 .
PowerShell: cleanUp Delete all backup and auto-save files. 10 .
PowerShell test harness 15 .
answers.txt commentary on comparative ease of scripting 15 .
answers.txt on performance comparison 15 .
Late submission -2% per day late; not accepted after 2 days -- .
Extraneous files submitted: -2 points per file -- .
Files were not submitted using turnin program: -10 points -- .
Total 100 .
Copyright © 2011 pmateti@wright.edu