Task 2
Topic: bash scripting.
Submission: You will create a bash script called userid_q2.sh where userid is your student number. This file must be in the Q2 directory of your repository. More files can be included, but these are the minimum.
You are working in the IT section of a new local media company that creates short videos of local events and makes them available for viewing via their website. The reporters upload their videos via an app which places the files directly into a specific directory (∼/dailyingest) on your system. You are tasked with developing a bash script that will provide a simple way to categorise the videos so they can be easily accessed on the basis of TOPIC, DATE, or REPORTER. All the files that are uploaded daily have a structured filename as follows:
DATE-TOPIC-REPORTER-a-title-consisting-of-words-separated-by-dashes.mp4
For example, on 15 August 2022 we have received the following files:
~/dailyingest/20220815-sport-Sam-Toowoomba-Raiders-Ready-for-New-Season.mp4
~/dailyingest/20220815-politics-Anne-Local-Candidates-for-Council-Meet.mp4
~/dailyingest/20220815-technology-Sophie-Child-Prodigy-Develops-Own-App.mp4
Topic names as well as reporter names consist of single words only and do not contain dashes or other non-letter characters. They are:
Topic: Reporter:
- sport - Sam
- politics - Sophie
- business - Michael
- family - Brett
- technology - Anne
You have already set up a directory structure to easily access video files, similar to:
~/shortvideos/byDate/
~/shortvideos/byReporter/Sam
~/shortvideos/byTopic/sport
~/badfiles
You now need to develop a bash script that processes the daily video files and places either the file itself OR a link to it in these directories, as follows:
1. all files in ∼/dailydigest will be moved to ∼/shortvideos/byDate
2. for each video file, a symbolic link will be placed in the directory ∼/shortvideos/ byReporter/REPORTERNAME
For example, for the first file listed above, a symbolic link (with the same name) will be placed in ∼/shortvideos/byReporter/Sam pointing to ∼/shortvideos/byDate/ 20220815-sport-Sam-Toowoomba-Raiders-Ready-for-New-Season.mp4
3. for each video file, a symbolic link will be placed in the directory ∼/shortvideos/ byTopics/TOPICNAME
For example, for the third file listed above, a symbolic link (with the same name) will be placed in ∼/shortvideos/byTopic/technology pointing to ∼/shortvideos/ byDate/20220815-technology-Sophie-Child-Prodigy-Develops-Her-Own-App.mp4
Your script should allow users to specify replacement directories for the default directories ∼/dailyingest, ∼/shortvideos, and ∼/badfiles; if no replacements are specified as arguments, the defaults will be used.
Your script should check that the target directories exist and can be written to. If a particular directory (such as ∼/shortvideos/byReporter/Anne) doesn’t exist yet, your script must create it first.
Your script should validate the filename structure of each file in ∼/dailyingest This
includes checking for correct Topics and Reporters (no new topic or reporter names
will appear other than those listed above). If a filename does not meet the required
structure, this must be reported on STDERR, and the file will be moved to directory
∼/badfiles.
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.