Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Linear Bash Scripting Objective In this assignment, your goal is to automate the creation of a file directory structure for a year's worth of daily

Linear Bash Scripting
Objective
In this assignment, your goal is to automate the creation of a file directory structure for a year's worth of daily blog entries for a given year. Your script should be called create_calendar_blog.sh.
(Note: if you are a student who has used bash scripting before, you are free to make this as advanced as you want as long as you complete the goal of the assignment.)
Assignment Restrictions
At no point in this assignment may you use an absolute path (starting from root). We need scripts that are generalizable to everyone and do not have your PID in the path. This also means that you cannot have a ~ in your script. Everything in this script should be completed with relative paths.
You should assume that the script will be run from the directory where the calendar folder is being created. If you were to run ls, you would see both your script and the _calendar in the same folder after the script finishes running.
You may not hardcode this assignment. We do not want to see 365 touch commands or 12 mkdir commands. Put some thought into how to make this easier on yourself before you start hacking out a script. The TAs will be checking that you did not hardcode this assignment.
Creating the File System Structure
Your script should create a directory called _calendar where is the year entered as a command line argument to the script.
For example, if the script takes 2018 as an argument, your directory should be called 2018_calendar.
Inside of your top-level calendar folder, you should create one folder per month, called Month01 through Month12.
Within each month folder, you should create the correct number of files cooresponding to the number of days in the month. We will ignore leap years. For Month01, there should be 31 files called Day01.txt, Day02.txt,... Day31.txt. For Month02, there should be 28 files called Day01.txt, Day02.txt,... Day28.txt.
Important Information
Working with Parameters to Scripts
You will be given a year as a parameter to your Bash script. When you call a script like this:
./my_script param1 param2
you can access the arguments of that script within the script using $0, $1, etc. So param1 above is stored in $1, param2 in $2 and so on if you have more parameters.
Working with Ranges in Scripts
If it wasn't clear, the goal of this assignment is not to have you write 365 touch commands to create files. Instead, we want you to use the capabilities of the scripting language to make your job easier.
One such capability is the ability to use a range. For example:
touch input{A..D}.txt
will create 4 files: inputA.txt, inputB.txt, inputC.txt, and inputD.txt.
Think about how you might make use of this range capability to simplify the amount of work you need to do. This assignment can be completed without any conditional logic. That means no if statements and no loops.
Changing Directories within Scripts
You are allowed to change where you are located during scripting. Just run cd commands like normal to move up and down through your directory structure. You are not limited to staying in one location.
However, it is possible to do this assignment without moving frequently around directories. Consider how you might run some of the commands you'd like to use without moving from your current location.
Testing
Running Your Script
To run your script, you need to provide the name of your script and an argument representing the year of the calendar you want to create. In our tests, we will never provide an empty year or a non-numerical year, so you do not need to test for these conditions.
./create_calendar_blog.sh
You will likely need to remove the old version that your script created to test it again. To quickly remove a directory structure without first having to remove the contents of subfolders, consider using the rm -r command. -r indicates that the directory structure should be removed recursively. For example, if I run rm -r 2020_calendar, I will remove 2020_calendar and all folders and contents inside of it. You should be extremely careful when using this command to not accidentally delete things you do not want to delete.
We have provided a second script, careful_remove.sh, to help out. This script will double check with you before running the rm -r command. Feel free to use it if you wish.
./careful_remove.sh
For all of these scripts, remember that you may need to modify your access permissions. When downloading scripts from Canvas, you will likely not automatically have execute permissions. Use the chmod command to grant yourself execute permissions to be able to run the scripts.
careful_remove.shDownload careful_remove.sh
Checking Your Script
We will provide a Python script for you to use to test whether your script is producing the correct set of files or not. You run a Python script the same way you run any other script:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

Describe how to train managers to coach employees. page 404

Answered: 1 week ago

Question

Discuss the steps in the development planning process. page 381

Answered: 1 week ago