Answered step by step
Verified Expert Solution
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 createcalendarblog.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 touch commands or 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 as an argument, your directory should be called calendar.
Inside of your toplevel calendar folder, you should create one folder per month, called Month through Month
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 Month there should be files called Daytxt Daytxt Daytxt For Month there should be files called Daytxt Daytxt Daytxt
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:
myscript param param
you can access the arguments of that script within the script using $ $ etc. So param above is stored in $ param in $ 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 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 inputADtxt
will create 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 nonnumerical year, so you do not need to test for these conditions.
createcalendarblog.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 calendar, I will remove 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, carefulremove.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.
carefulremove.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.
carefulremove.shDownload carefulremove.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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started