Operating Systems

Operating doggedly...

Command-Line Hacking

This is a practical exercise. You have approximately an hour. There are no restrictions placed on the resources you may use in completing this quiz, as long as you abide by the course syllabus. (In other words: you are welcome and encouraged to work with a partner, as long as the outcome is that you both understand the material.)

You are required, in this exercise, to use either vi or emacs for your authoring. Cheat sheets to help you with the commands for those editors will be provided.

Echoing Arguments

  • Create a new script file called assignment-submission.bash.

  • This script should take one argument from the command line, and echo that argument back to the user. Demonstrate this to the instructor when you succeed.

Cleaning Up Submissions

  • The argument you are given should be a directory. Check that it is; exit if it is not. Continue in the even that you were given a valid directory.

To exit, the command you want to use is exit.

Make Sure it is Ours

To make sure the directory we've been given is actually an "assignment," we'll look for a file called .osf13 in that directory.

In your example directory, create an empty file called .osf13.

In your script, add another condition, so that we make sure that we've been given a directory AND that the directory contains this file. If the special file exists, continue; if not, echo an error so that the user knows why your script exited.

Cleanup

We will assume the directory you are given is something you might be submitting for this course. That being the case, there should only be two kinds of files in the directory: Markdown files or LaTeX sources.

  • Use pushd to enter the directory.

  • Delete all temporary files in the directory that your text editor might create. For example, my editors often create *.swp, *~, or things I can't remember.

  • Delete all the mess that LaTeX leaves behind. Assume these are files ending in .log, .aux, .out, and .toc.

  • Use popd to exit the directory.

Compress the Directory

  • Create a tarfile of the directory. The tape archive command looks like this:

tar -caf filename.tar sourcedir/

The filename of your tape archive should be the same as the name of the directory.

After creating the .tar file, compress it with gzip.

gzip filename.tar

This will remove the tarfile, and leave you with a file called filename.tar.gz. Again, filename should be the same as the name of the directory.

Test

Download this test script.

wget http://tinyurl.com/bash-test-script-py

Or, you can clone the gist:

git clone https://gist.github.com/6378127.git

Make sure it is set to be executable:

chmod 755 bash-test-script.py

Then, run it.

python bash-test-script.py

It will do the following:

  1. Create a directory called "assignment-n", where n is the number of seconds since the epoch.
  2. Populate that directory with a bunch of random files, some "valid" and some "garbage."
  3. Run your script. It should be named assignment-submission.bash, remember.
  4. Check that the file that your script generated (which should have been called "assignment-n.tar.gz") contains the correct files.

Submission

As always, written work should be submitted as a Markdown document (.md) or a compressed file containing the LaTeX source of your report (.tar.gz) and a compiled PDF of the output. LaTeX submissions should be sources only, without temporary files (.aux, .log, etc.).

On Linux, you might use UberWriter or ReText for Markdown, and on Windows, MarkdownPad. Any editor works for LaTeX, although some prefer tools that are designed for the purpose.

Assignment: Command Line Hacking

Naming Convention: username-command-line-hacking

Moodle Link: http://moodle2.berea.edu/course/view.php?id=2243

The Test Script

The test script is included here for reference.



This website is provided under a CC BY-SA license by the The Berea CS Department.
Fall 2013 offering of taught by Matt Jadud