I'm having problems with this assignment. I know how to do these basic unix "if" and "then" statements) What I am having trouble with is putting my script together. I started with #!/bin/bash and not sure how to continue. I have to indicate the source and destination folders, and make each a parameter, which I dont know how to do. So could please someone guide me on how to get this script started the right way?
- The problem statement, all variables and given/known data:
#!/bin/bash
#########################################################################
# DO NOTE REMOVE OR CHANGE THIS BLOCK WHILE YOU COMPLETE THE ASSIGNMENT
# ASSIGNMENTS COMPLETED WITHOUT THIS BLOCK INTACT WILL NOT BE GRADED
#
# ULI101 - WINTER 2012
# ASSIGNMENT 2 BY: John Doughtski
#
#
# PLEASE REMEMBER THAT SHARING YOUR SOLUTION WITH ANOTHER STUDENT
# IN PART OR IN ENTIRETY IS A VIOLATION OF THE ACADEMIC POLICY
#
# BIGBROTHER COMMAND VERIFIES THAT YOU COMPLETE THE WORK INDEPENDENTLY
# BY RECORDING YOUR PROGRESS AND COLLECTING STATISTICAL DATA
#
# IF YOU DELETE OR DAMAGE THE COMMAND BELOW BY ACCIDENT, YOU CAN RETRIEVE
# THE ORIGINAL BY ISSUING THE ASSIGNMENT START COMMAND AGAIN
bigbrother e5679c3fd97e3d34182b727a9241a3bc4b9db131 momo
#########################################################################
# ASSIGNMENT 2 INSTRUCTIONS, PERSONALIZED FOR jdoughtski
# Create a BASH shell script called momo (My Own Music Organizer)
# in ~/uli101.a2/ directory according to the following specifications:"
# Your script will be used to organize a collection of MP3 files.
# Files to be processed are expected to reside in a single directory
# (no sub-directories).
# Your script, must create subdirectories for each artist and
# create symbolic links to each song in appropriate directories.
# The script usage will be as follows:
# momo source_directory [destination directory]
# If the destination directory is not provided, the present working directory
# is the destination.
# The name of the file/link will be based on album and song name
# in the following format: Album _ SongTitle.mp3
# Additional information:
# - All song metadata will be based on information in ID3v1 tags
# - Assume that all .mp3 files in the source directory have a valid ID3v1 tag
# (ID3v1 details can be found on-line
# - .mp3 extensions can have any combination of upper- and lower-case letters
# - Assume that you have read permission for the source directory
# and write permission for destination
# - Ignore files in the source directory that do not have the .mp3 extension
# - Display an error message and exit with status 2 if no parameters are given
# - Display an error message and exit with status 3 if source is not a directory
# - Display an error message and exit with status 4 if destination
# does not exist or is not a directory
# TIP: Keep a secure backup of your script outside of other users' access.
# Practice files can be found on matrix in ~uli101/public/songs[1-5]
# directories. Although they are not actual mp3 files, they contain
# valid ID3v1 tags.
# In addition to creating a directory/file structure, your script must create
# a valid HTML 5 report file containing the output of the tree command,
# showing the above structure. The report will also show a footer section
# showing the source directory path, date/time when report was created
# and number of artist and songs organized.
# Although it is not a requirement, feel free to set colours, fonts and other
# visual attributes of your report.
# Place the report file in the output directory and call it: .index.html
# TIP: Have a dedicated testing directory for output and make a symbolic link
# in your ~/public_html directory to your report file in there.
# This way it will be easy to view and validate the report using your browser.
# Your script will produce a single line of output to the shell
# (other than possible error messages), containing two numbers, separated by
# a single space: number of artists processed and number of songs processed.
# Check your progress using the following command: uli101.a2.check
# Submit your completed assignment using the following command: uli101.a2.submit
# PLEASE NOTE THAT PLAGIARISM CASES WILL BE HANDLED ACCORDING TO THE ACADEMIC
# POLICY. YOUR SCRIPT MUST BE WRITTEN WITHOUT HELP FROM OTHERS AND YOU ARE NOT
# ALLOWED TO ACCESS OTHER STUDENTS' ASSIGNMENTS
# DO NOT SHARE YOUR SOLUTION. ASK ONLY YOUR PROFESSOR FOR HELP.
### TO DO: Check if at least one parameter is supplied, exit on error
if [ $# ]
then
exit
fi
### TO DO: Check if first parameter is a directory, exit on error
# Set the destination to default (pwd) if no destination is provided
if [ $# -lt 2 ]
then
set "$1" .
fi
### TO DO: Check if destination exists and is a directory, exit on error
for path in $(### TO DO: Get the list of mp3 files in the source directory)
do
# Extract the ID3 TAG from file
tag=$(tail -c 128 $path)
# Extract the song name and trim space padding
song_name=$(echo "$tag" | cut -c 4-33 | sed -r 's/ +$//')
### TO DO: Extract the artist and album, trim both
### TO DO: Create a directory for artist in the destination directory
### (if not already there)
### TO DO: Create a symbolic link to the song in the artist's directory
done
### TO DO: Finish the output line to the terminal
echo
cat << TOP > $2/### TO DO: Set the report file name here
<!DOCTYPE html>
<html>
<head>
<title>ID3 Report Page</title>
</head>
<body>
<h2>ID3 Report Page</h2>
TOP
### TO DO: Display the tree for the artists/songs directory structure
### TO DO: Add the path to the source directory to the report
### TO DO: Add current date/time to the report
### TO DO: Add to the report how many artists and songs were processed
echo "</body></html>" >> $2/### TO DO: Set the report file name here
-
Relevant commands, code, scripts, algorithms:
Vi editor, basic unix scripting. -
The attempts at a solution (include all code and scripts):
!#/bin/bash
momo source_directory [destination directory]
source="/home/uli101/public/songs1"
destination="/home/jdoughski/uli101.a2"
#Check if at least 1 parameter is supplied, exit on error
if [ $# -lt 1 ]
then
echo "No parameters found, add at least 1 parameter"
exit 2
fi
# Make sure first parameter(source) is a directory, exit on error
if [ ! -d "$0" ]
then
echo "First paramer must be a directory"
exit 3
fi
# Check if destination exists and is a directory, exit on error
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Seneca @ York, Toronto, Ontario, Canada, Mark Buchner, ULI101C
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).