CEG 233: Linux and Windows 

Lab on Scripting with BASH and CMD

   

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
  2. Learn fundamentals of Linux bash scripting
  3. Learn fundamentals of Windows cmd scripting

Background

The two articles on Scripting by Prabhaker Mateti in the References are Required Reading.

This Lab is about scripting.  It uses MP3 files as a domain where scripting can be usefully deployed.  It is not crucial that you understand the internal structure of MP3 files.  It is sufficient to know that the ID3 tags are embedded with the MP3 files.  For further details on MP3 files, read the Wiki article mentioned in the References.

You will be creating a bunch of MP3 files in a TESTMP3 directory.  These are "artificially" created, not playable "music" files.  But the tool we use to manipulate, namely id3tool in Linux and  in Windows, does not touch the musical content.  The tool manipulates only the ID3V1 tags.  Invoking id3tool with no arguments displays its usage. Invoking id3tool with the name of an MP3 file as its only argument displays its ID3V1 tags. See the References for download details of the tool.

For our experimental purpose, this TESTMP3 will contain about a 100 files.  These files do have Album, Artist, and Year tags.  They may or may not have a track number or title tags. Assume that these tags do not have white spaces. You will be creating subdirectories based on the Album name and the Year as in Album-Year, and moving into each Album directory the files of that album.  You will then be renaming each file based on the track number, album, and artist as in nn-Album-Artist.mp3.

Here is an example of how a dummy MP3 file (name = first argument) whose tags are Album (second argument), Artist (third argument), Year (fourth argument) can be created in the current working directory.  Feel free to be more creative than this!  You may earn bonus points!

createOneDummyMP3File()
{
  echo > $1.mp3
  id3tool $1.mp3 -a $2 -r $3 -y $4
}
Obviously, in creating 100 dummy files, you need to come up with different file names, album names, etc.  Some of them should also have the  track number tag.

Exercise:  Discover what the following do:


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.

In Linux

  1. Copy the id3tool program binary into your home directory.  Setup id3tool as an alias to this.
  2. Develop a bash procedure called createTestMP3Files() that creates a subdirectory named TESTMP3 in the current working directory, and populates it with about a 100 dummy MP3 files as described in the Background.
  3. Develop a bash procedure called sortMP3Files() that "sorts" and moves MP3 files located in the source directory SOURCE given as the first argument into the destination directory DEST given as the second argument.
    1. Create a subdirectory in DEST for each new album name seen among the MP3 files of SOURCE.  If such a directory already exists in DEST, do not complain.
    2. Move an MP3 file with an album tag of AlbumX of SOURCE into DEST/AlbumX directory unless a file with that name already exists.  If so, let the MP3 file remain in SOURCE.
    3. Rename the MP3 files of album directories of DEST so that they are now of the form nn-Album-Artist.mp3.  If an MP3 file has no track number tag, use your judgment to give it a default tag number.
  4. Include the two procedures, and invocations to them in a script file named taggingMP3.sh.  It should (i) create an empty subdirectory named RESULTSMP3 in the current working directory, (ii) invoke createTestMP3Files,  (iii) long-list the directory TESTMP3,  (iv) invoke sortMP3Files TESTMP3 RESULTSMP3, and (v) recursively long-list the directories TESTMP3 and RESULTSMP3.

In Windows

  1. Develop a script taggingMP3.bat equivalent to the above in the cmd syntax.  Use standard commands that come with Windows cmd.  You must make use of procedures, perhaps one for each of the tasks above. 
  2. You may use the id3tool mentioned in the Background or any other similar tool that you have. 
  3. You may want to download and install sed for Windows, or use an equivalent tool.

Turnin

Note the number <n> of this Lab from the course home page and use L<n> as the first argument to turnin.  Read the Grading Sheet to determine what files must be submitted.

For 20 max bonus points, show us the evidence that you used your script on your collection of real MP3 files.

Link to Grading Sheet


Acknowledgements


References

  1. Prabhaker Mateti, Notes on Scripting with BASH, scriptingWithBASH.html.  Required Reading.
  2. Prabhaker Mateti, Notes on Scripting with CMD, scriptingWithCMD.html.   Required Reading.
  3. ID3 Tags http://en.wikipedia.org/wiki/Id3  Recommended Reading.
  4. id3tool is an open source contribution of http://nekohako.xware.cx/id3tool/ A program binary suitable for Ubuntu Gutsy Gibbon is located at:  /home/ceg233/ceg23300/bin/id3tool.  A Windows exe of id3tool is also located at: /home/ceg233/ceg23300/bin/id3tool.exe  Recommended Tool.
  5. sed for Windows is an open source contribution of http://gnuwin32.sourceforge.net/packages/sed.htm Recommended Tool.

.
Copyright © 2009 Prabhaker Mateti last edited: June 24, 2009