Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NAME: INSTRUCTIONS: PLEASE READ CAREFULLY AND ASK IF ANY QUESTIONS. USE THE Discussion Board on D2L TO GET SOME EXTRA HELP (NOT HOW TO DO

NAME: INSTRUCTIONS: PLEASE READ CAREFULLY AND ASK IF ANY QUESTIONS. USE THE Discussion Board on D2L TO GET SOME EXTRA HELP (NOT HOW TO DO IT, BUT HOW TO APPROACH A PROBLEM) 1)Write a bourne (bash) script that will continuously display the following menu and then waits for a user selection. The menu still stop execution when user selects option 9. Welcome to Matt's (your name) main menu 1 -- Display users currently logged in 2 -- Display a calendar for a specific month and year (user is asked for a month and year to be displayed) 3 -- Display the current directory path 4 -- Change directory 5 -- Long listing of visible files in the current directory 6 -- Display current time and date and calendar 7 -- Start the vi editor (user will be asked which file to open if the file does not exist, then create new one) 8 -- Email a file to a user (use the emailer program created in assignment 6 but it will need a few error checks) 9 -- Quit Make your selection: This assignment is a little different from the past one since you will need to introduce more details in the options, including protection against many inputs, such as the existence of a file name to attach to email, etc. Specs for your program: The selection of an item from the menu should perform the desired action and the menu should be displayed constantly until the user selects Quit, then it will take to user to the shell prompt. Clear (clear command) after or before every action so the screen is not cluttered. So, user selects option 1 or A, users are shown the output of that option, then user may be asked to press return or space and the menu shows up again, remember the option read -n1 that could work nicely in this case. Remember this is not done by recalling the script, but user the proper loop structure so the menu repeats. Item 2 - look at the cal command and its options. You will ask the user which month and year they would like to see and the chosen calendar would be displayed. HINT: what happens if the user types dates outside of the calendar range.. like year 23049934? protect that using if statements to select range of value like: "please enter a year between 1950 and 2030" Use the if statements to protect it so if a user enters 1454 for instance he/she will be prompted with "out of range message". The cal command itself does display an error messages if out of range values are entered, but change those default errors with your own error checking. I am checking your understanding of the if statement. Item 4 - should prompt the user for a directory where they would like to go. If the directory exists and accessible, change to that directory (note, if no directory is entered you must change to your home directory.) Problem: what happens if the user types ~ or $HOME for that option will it work? try to fix that problem. (HINT: Look at the eval command that will help with this problem) Item 5 - remember that you may have many files on a directory and you will need to stop one page at a time, pipe to more if the output is too long, other commands also may go over a page, so use | more. Item 7 - should prompt the user for a file and if the file exists and is a readable ordinary file, edit that file using the vi editor, otherwise create that file. Also protect that so the user can not open in vi a binary file or a directory. HINT: You can use the command file to find out if the file is ordinary text file combined with the grep command. Item 8 Some of the work on this option is already done in a previous assignment. You should prompt the user for a username, and if the username exists on our syccuxas01 system, it should then prompt for a file name much like item 7 with the protections not allowing users to attach binary files, or dirs, also prompt the user to enter a subject. HINT. use grep to find if the user exists in /etc/passwd file.). When I mean attach I refer to the < (input redirect) not the attachment of a file that will show and attachment on the top of the email. So, this is like assignment 6 mail -s "subject" usertosend < filetobesent But don't forget to implement the error checks and other features as required. Notes: Assignment 7 explained http://spot.pcc.edu/~wmorales/cs140u/CS140u_Assignment7_explained.m4v (need quicktime player or another compatible player) A comment block such as those on the examples seen in the lecture must be on top of your script file with your name, date, description of the program. Make sure that the first line indicates the shell to be used #!/bin/bash Make sure to document your program with comments in the various areas of your program. Implementing functions on your program will make it much more elegant and easier to debug it. You can also use $bash -x program.bash for some debugging. Do not try to write the script all at once. Do it one step at a time. For example, first write the loop that displays the menu. Make sure that it works then implement each menu time, one by one it in the full program. You may want to use functions to make your program more efficient. Good bash programming practices (also one way to find if the user exist on the system, emailer error checking section :-) ) https://www.networkworld.com/article/2694433/unix-good-coding-practices-for-bash.html

Criteria

Requirements

Comments appropriate, not on line 1

. Note that comments are very important to identify sections of the program and their purpose. A good programmer always documents well the program for future review. I hear this constantly from folks in the industry who need to maintain old software. They tell me how poorly the program was documented and in many instances they have to start it from scratch since they cannot understand the program.

Example

#!/bin/bash

################################################################### # walter morales CS 140u - date: XX XX XX # This script clears the terminal, displays a greeting and gives information # about currently connected users. The two example variables are set and # displayed.

###################################################################

clear # clear terminal window

echo "The script starts now."

echo "Hi, $USER!" # Dollar sign is used to get content of variable

echo

.

It is not necessary to repeat comments such as clear # clear terminal window , if the command is used in many parts of the program.

Just having one comment for this line is enough. You did have a lab activity to write comments on the programs uon.sh, svi.sh preceding this assignment so you would understand the importance of documenting your programs.

/ 21.4291

item 1 menuing & presentation logic

use of clear, 1-key inputs , proper outer loop design

/ 21.4291

item 2 range checking inputs on cal option

prompts

chosen calendar would be displayed.

range checking w/ if statement.

/ 21.4291

Item 4 prompts defaults and handles shortcuts

prompt for a directory, defaults to home . friendly handling of ~ or $HOME directory inputs

/ 21.4291

always | more (item 5 on specsheet)

Many commands might produce a full screen of output and you will not be able to see the what was on the top, always | more. This would be the case of ls, finger, cat filename

/ 21.4291

check user file exists, is ordinary file before launching vim. (Item 7)

should prompt the user for a file and if the file exists and is a readable ordinary file,

edit that file using the vi editor,

otherwise create that file.

Also protect that so the user can not open in vi a binary file or a directory. HINT: You can use the command file to find out if the file is ordinary text file combined with the grep command.

/ 21.4291

Item 8 specs checks

prompts for subject, recipient, filename

checks user exists

prompts for the filename

disallows for binary files and directory attachments

/ 21.4291

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

Students also viewed these Databases questions

Question

3. Contrast relational contexts in organizations

Answered: 1 week ago

Question

2. Describe ways in which organizational culture is communicated

Answered: 1 week ago

Question

1. Describe and compare approaches to managing an organization

Answered: 1 week ago