Assignment 7

Back Up

horizontal rule

Home
Assignment 1
Assignment 2
Assignment 3
Assignment 4
Assignment 5
Assignment 6
Assignment 7

 

Assignment 7

CS 140U
150 POINTS


150 POINTS Due date announced in the discussion board under Weekly postings and the calendar Please email a copy of your program to wmorales@syccuxfs01.pcc.edu and a copy in the assignment drop box, renaming it .txt and converting it to DOS first. This assignment will not be accepted late.

 

 

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 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.)

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 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.

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 the desired commands one-by-one add for each selectable item. You may want to use functions to make your program more efficient.

Submit:

 

Email your script to wmorales@syccuxas01.pcc.edu , place a copy in the assignment dropbox.

Place a copy in the assignment dropbox. Before uploading the script  menu7_script.sh, make a backup copy, rename it in the linux and call it menu7_script.sh.txt, convert it to DOS format using the command unix2dos, then transfer it to your computer using psftp or filezilla, then upload it.

START ON IT SOON!!!!

 

 

 

horizontal rule

Back to CS140U Homepage
This page was last modified September 26, 2004
wmorales@pcc.edu