Question: Need a bash script that is runnable in a unix environment specifically Putty and does the following. 1)Write a bourne (bash) script that will continuously
Need a bash script that is runnable in a unix environment specifically Putty and does the following.
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 Walter'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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
